当@ 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`
答案 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
)