怎么在where子句中用case when + exists
1个回答
2017-09-20
展开全部
怎么在where子句中用case when + exists
SELECT (CASE WHEN MASTERJOB = '' THEN JOBNO ELSE MASTERJOB END)WO,JOBNO,CHILDJOB,CODE,BDESC,P_CODE,
(SELECT TOP 1 BDESC FROM PRO WHERE CODE=RESVT.P_CODE)CBDESC,QTY,UNIT,LOC,
(CASE WHEN exists(SELECT top 1 TAXUP
FROM ANT B LEFT JOIN ANTUDF A ON (B.PANNO=A.PANNO and B.ITEMNO=A.ITEMNO)
WHERE B.CODE=RESVT.CODE AND A.WO like @gd AND B.TAXUP > 0 )
THEN
(SELECT top 1 TAXUP
FROM ANT B LEFT JOIN ANTUDF A ON (B.PANNO=A.PANNO and B.ITEMNO=A.ITEMNO)
SELECT (CASE WHEN MASTERJOB = '' THEN JOBNO ELSE MASTERJOB END)WO,JOBNO,CHILDJOB,CODE,BDESC,P_CODE,
(SELECT TOP 1 BDESC FROM PRO WHERE CODE=RESVT.P_CODE)CBDESC,QTY,UNIT,LOC,
(CASE WHEN exists(SELECT top 1 TAXUP
FROM ANT B LEFT JOIN ANTUDF A ON (B.PANNO=A.PANNO and B.ITEMNO=A.ITEMNO)
WHERE B.CODE=RESVT.CODE AND A.WO like @gd AND B.TAXUP > 0 )
THEN
(SELECT top 1 TAXUP
FROM ANT B LEFT JOIN ANTUDF A ON (B.PANNO=A.PANNO and B.ITEMNO=A.ITEMNO)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询