最終スクリプトを変更して、除外スイッチも含めるにはどうすればよいですか? 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;