3
可以在CASE..THEN
中使用IN
嗎?IN CASE THEN表達式中的結果表達式中的IN語句
WHERE
record.field =
CASE
WHEN @flag = 1 THEN a
WHEN @flag = 2 THEN IN (b, c)
END
或者如何改寫這樣的條件?
可以在CASE..THEN
中使用IN
嗎?IN CASE THEN表達式中的結果表達式中的IN語句
WHERE
record.field =
CASE
WHEN @flag = 1 THEN a
WHEN @flag = 2 THEN IN (b, c)
END
或者如何改寫這樣的條件?
對不起,沒有:
WHERE
(@flag = 1 AND record.field = a)
OR
(@flag = 2 AND record.field IN (b, c))
嘗試:
WHERE (@flag = 1 AND record.field = a)
OR (@flag = 2 AND record.field IN (b, c))
它可能是更好地嘗試在價值加入並使用索引:
DECLARE @Table (ValueOf int)
INSERT INTO @Table ((ValueOf)
SELECT a WHERE @flag = 1
UNION SELECT b WHERE @flag = 2
UNION SELECT c WHERE @flag = 2
SELECT
....
FROM ... x
INNER JOIN @Table t ON x...=t.ValueOf