我需要創建一個查詢,看起來像這樣:CASE語句內部存在
SELECT attr
FROM SomeTable B
WHERE EXISTS
(CASE WHEN B.some_attr = 0
THEN (SELECT x FROM C WHERE B.z = z)
WHEN B.some_attr = 1
THEN (SELECT x FROM D WHERE B.z = x)
END)
但是SQL Server將拒絕執行此帶來一些語法錯誤。
如何修改此查詢以使其工作?
編輯:我加入了錯誤:
Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'CASE'.
Msg 156, Level 15, State 1, Line 6 Incorrect syntax near the keyword 'WHEN'.
Msg 102, Level 15, State 1, Line 8 Incorrect syntax near ')'.
「有些語法錯誤」將是一個很大的幫助大家誰願意幫助你。 – DaveRlz 2012-07-20 14:00:45