SQL 2008/2005
我在Case语句中有SQL查询语法问题 - 我正在寻求一些帮助。这是Case Statement上的一个简单的SQL语法问题。我已经在我的查询中评论了这个场景,我已经附上了..请建议继续前进..!
select
stuff(Dr.DrugNDCNbr,
case when Dr.DrugNDCType in (50, 56) then 1
when Dr.DrugNDCType in (51, 57) then 6
when Dr.DrugNDCType = 52 then 10
-- when Dr.DrugNDCType = 49 then -- DO NOTHING .. GIVE THE ACTUAL VALUE
end, 0, '0')
from drug Dr
where Dr.drugnbrkey = 6284
答案 0 :(得分:6)
它是您需要的嵌套CASE 表达式
select
case
when Dr.DrugNDCType = 49 then Dr.DrugNDCNbr
else
stuff ( Dr.DrugNDCNbr,
case
when Dr.DrugNDCType in (50, 56) then 1
when Dr.DrugNDCType in (51, 57) then 6
when Dr.DrugNDCType = 52 then 10
end, 0, '0')
end
from drug Dr
where Dr.drugnbrkey = 6284