我想使用IF
和ELSE
条件执行不同的查询...
CASE WHEN (SELECT COUNT(*) FROM dcdetail AS d LEFT JOIN finalbilldetail AS f ON d.itemid = f.itemid WHERE ISNULL(d.itemcolorid, '') = ISNULL(f.itemcolorid,'') AND f.itemid IS NULL AND d.id = 12) > 0 THEN SELECT dm.ID ,dm.Status ,dm.EntryDate ,dm.EntryTime ,ci.cusid ,ci.cusname ,ci.cuscontact FROM DcMaster AS dm LEFT OUTER JOIN RegCustomerInfo AS ci ON dm.customerID = ci.CusID WHERE dm.customerid = 8 ELSE (Other Query) END
答案 0 :(得分:0)
在SQL Server CASE
中不能用于控制流。请改用IF
。
IF (SELECT count(*)
...) > 0
BEGIN
SELECT ...
END
ELSE
BEGIN
SELECT ...
END;