如何修改最终脚本以使其也具有排除开关?我不想EXISTS
在最终脚本中使用:
SELECT MyField = 'x' INTO #Data
UNION SELECT MyField = 'y'
UNION SELECT MyField = 'z'
UNION SELECT MyField = 'j'
UNION SELECT MyField = 'q'
UNION SELECT MyField = NULL;
SELECT MyField = 'j' INTO #Exclusions
UNION SELECT MyField = 'q'
UNION SELECT MyField = NULL;
DECLARE @ShowAll TINYINT = 1; -->>exceptions "switch" is turned ON so all data returned
SELECT *
FROM #Data d
WHERE @ShowAll = 1 OR
(
EXISTS
(
SELECT d.MyField
EXCEPT
SELECT MyField FROM #Exclusions
)
);
--can I simplify and get rid of the EXISTS but still include a switch based on @ShowAll ?
SELECT *
FROM #Data d
EXCEPT
SELECT MyField FROM #Exclusions;