0

このクエリで「@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)
4

1 に答える 1

0

私は次のようなものを試してみます:

avi.result= 
CASE WHEN avi.AnalysisName = 'ABO' 
THEN @abo 
ELSE 
    CASE WHEN avi.AnalysisName = 'RH' 
    THEN left(@rh,3) 
    END 
END

ケースの結果は、avi.result の型と互換性のある型でなければなりません。

私見、ELSEを2番目/内側のケースに入れるか、次の構文を使用する必要があります。

avi.result= 
CASE avi.AnalysisName 
    WHEN 'ABO' THEN @abo  
    WHEN 'RH' THEN left(@rh,3)  
    ELSE 'DEF' 
END
于 2012-12-27T08:35:08.530 に答える