このクエリで「@abo is null」と「@rh is null」を渡す方法....これはエラーになります...私はこれをやっています
select Distinct m.donorId,m.customid, FirstName + ' ' + Isnull(MiddleName,' ') + ' ' + isNull(LastName,'') as donorName from m_donor as m inner join phlebotomyDetail as phy on m.DonorID=phy.DonorID left outer join AVIRaw as avi ON @prefix + RIGHT('000000' + CAST(m.DonorID AS VARCHAR(6)), 6) = avi.sampleid
Where (m.donorId = @donorid OR @donorid is null) and
(m.DOB = @todate OR @todate Is Null) and
(m.FirstName Like + '%' + @fullname + '%' OR m.MiddleName Like + '%' + @fullname + '%' OR m.LastName Like +'%' + @fullname + '%' OR @fullname Is Null) and
(m.cellPhone Like +'%' + @phone + '%' OR m.HomePhone Like + '%' + @phone + '%' OR m.WorkPhone Like + '%' + @phone + '%' OR m.OtherPhone Like + '%' + @phone + '%' OR @phone Is Null) and
(m.CustomID Like '%' + @custid OR @custid Is Null) AND
(phy.BagNumber=@bagno OR @bagno is NULL) AND
(phy.SegmentNo=@segno OR @segno is NULL ) AND
(avi.result= CASE WHEN avi.AnalysisName = 'ABO' THEN @abo or @abo is null ELSE CASE WHEN avi.AnalysisName = 'RH' THEN left(@rh,3) or @abo is null END END)