PersonId ============================ ========= 表名首页 ------- HomeId HomeNumber HomeName 我想搜索sql查询... 如... .. 如果我想找人名,Person HomeNumber和NoticeTitle那么如何查找以下查询是行不通的..I have three table as follow-------table name Person----------PersonIdHomeIdFirstNameEmailGenderPassword====================================table name NoticeBoard-------------------------NoticeBoardIdNoticeTitleNoticeCreationDatePersonId=====================================table name Home-------HomeIdHomeNumberHomeNameI want to make search sql query...as like..If I want to find person name, Person HomeNumber and NoticeTitle so how to find following query can not work..ALTER PROCEDURE dbo.sp_Custom_Select_Complain(@PersonId int = NULL,@FirstName varchar(50) = NULL,@Gender varchar(50) = NULL,@ComplainId int = NULL,@ComplainTitle varchar(100) = NULL,@ComplainInfo varchar(400) = NULL,@HomeId int = NULL,@HomeNumber int = Null,@HomeName varchar(50) = Null)ASselectP.FirstName,P.Gender,C.ComplainTitle,C.ComplainInfo,H.HomeNumber,H.HomeNameFrom Person PInner Join Complain C On C.PostId = P.PostIdInner Join Home H On H.HomeId = P.HomeIdWhere(@PersonId Is Null Or P.PersonId = @PersonId)AND(@FirstName Is Null Or P.FirstName LIKE '%' + @FirstName + '%')AND(@Gender Is Null Or P.Gender = @Gender)AND(@ComplainTitle Is Null Or C.ComplainTitle LIKE '%' + @ComplainTitle + '%')AND(@ComplainInfo Is Null Or C.ComplainInfo LIKE '%' + @ComplainInfo + '%')RETURN ------------------- --------------------------- 请帮帮我......----------------------------------------------please help me...推荐答案尝试将连接更改为左外连接Try changing your joins to left outer joins 你检查空值传递给整数值。 示例: int? PersonId = Null 或 int? PersonId = 1Hi,did u check null value passing to integer value.Example :int? PersonId = NullORint? PersonId = 1 这篇关于在mysql中加入三个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-10 23:57