SQL WHEN CASE

来源:互联网 发布:软件开发合作模式 编辑:程序博客网 时间:2024/05/17 23:02

 sql="select id,qiye,hangye,zhengche,jb,sh,dizhi,tel,dianji,daima,(case sheng when '"&sheng&"' then '6' else '2' end) as aa from d_zhuce where  sheng='"&sheng&"' and xian like '%"&xian&"%'  union select a.id as id,a.qiye as qiye,a.hangye as hangye,a.zhengche as zhengche,a.jb as jb,a.sh as sh,b.dizhi as dizhi,b.tel as tel,a.dianji as dianji,b.daima,(case b.dizhi when '"&sheng&"' then '6' else '2' end) as aa from d_zhuce a inner join d_wangdian b on a.id=b.q_id where b.dizhi like '%"&xian&"%' and qylb='专线' order by aa,daima"