以下の作品
IF OBJECT_ID('TEMPDB..#Users') IS NOT NULL
BEGIN
DROP TABLE #Users
END;
CREATE TABLE #Users(UserAccountKey INT);
IF @Period IN ('Overall', 'Week1', 'Week2', 'Week3', 'Week4')
BEGIN
INSERT INTO #Users
SELECT UserAccountKey
FROM XXX c
WHERE c.Name NOT IN ('X', 'Y', 'Z', 'J', 'Q')
GROUP BY UserAccountKey
END
ELSE
BEGIN
INSERT INTO #Users
SELECT UserAccountKey
FROM XXX c
WHERE c.Name NOT IN ('X', 'Y')
GROUP BY UserAccountKey;
END;
これを単一のSQLステートメントに短縮することは可能ですか? 条件を条項IF
に移すことはできますか?WHERE