超急啊~!!!sql的多分支问题~~~
请教大家一下sql的多分支怎么写啊?
select Cxzb_nr,Cxzb_dw,Cxzb_dwxb from Cxzb where
case
when @jibie= '3 ' then Cxzb_dw=@danwei
when @jibie= '2 ' then Cxzb_dw=@xuesh
else Cxzb_dw=@www
end
------解决方案--------------------select Cxzb_nr,Cxzb_dw,Cxzb_dwxb from Cxzb where Cxzb_dw=
case
when @jibie= '3 ' then @danwei
when @jibie= '2 ' then @xuesh
else @www
end
------解决方案----------------------try
select Cxzb_nr,Cxzb_dw,Cxzb_dwxb from Cxzb where Cxzb_dw=
(case
when @jibie= '3 ' then @danwei
when @jibie= '2 ' then @xuesh
else @www
end)
and Cxzb_zw=
(case
when @jibie= '3 ' then @danwei
when @jibie= '2 ' then @xuesh
else @www
end)
------解决方案--------------------改用动态SQL吧