获取列为null的所有数据,而不是null和null(null和not null)

时间:2018-06-11 11:47:16

标签: sql-server

当@ se_withsiddhi ='Y'时,我得到所有数据,但是@ se_withsiddhi = null时只想检索空值而不是获取。

   declare @se_withsiddhi varchar
        set @se_withsiddhi = 'Y'
    select  JD.Job_No,
            INV.Bill_No,
            inv.BilledToSE 
    from    invoice INV
            left outer join Job_Details JD on JD.Job_ID = INV.Job_ID 
    where   JD.Job_No is not null 
            and INV.Bill_No is not null 
            AND isnull(INV.BilledToSE,'') = case @se_withsiddhi
                                            when 'Y' then isnull(INV.BilledToSE,'')
                                            when Null then ''
                                            else  null
                                            end`enter code here`

2 个答案:

答案 0 :(得分:1)

您需要对@se_withsiddhi使用isnull:

case isnull(@se_withsiddhi, '')
when 'Y' then isnull(INV.BilledToSE,'')
when '' then ''
else  null
END

答案 1 :(得分:0)

AND 
( 
   @se_withsiddhi='Y' or 
   @se_withsiddhi is null and INV.BilledToSE is null
)