我有以下查询,其中我试图根据位变量的值从表中返回不同的值。
有没有一种方法可以代替where条件使之起作用?
DECLARE @isAggregate bit = 0
SELECT
*
FROM
Fields
WHERE
FieldType
CASE
WHEN @isAggregate = 1 THEN = 'Aggregate'
WHEN @isAggregate = 0 THEN <> 'Aggregate'
END
答案 0 :(得分:3)
您可以使用布尔逻辑,情况expression
不能以这种方式工作:
where (@isAggregate = 1 and FieldType = 'Aggregate') or
(@isAggregate = 0 and FieldType <> 'Aggregate')