我有以下查詢:where子句中的SQL Case語句指定條件?
SELECT *
FROM dbo.tblOrders o
WHERE o.OrderId IN (SELECT [Value] FROM [dbo].[udf_GenerateVarcharTableFromStringList](@OrderId, ','))
AND
@ActiveInactive =
CASE
WHEN 'Active' THEN (o.[orderactivedate] > o.[orderinactivedate])
WHEN 'Inactive' THEN (o.[orderactivedate] < o.[orderinactivedate])
END
這將返回
An expression of non-boolean type specified in a context where a condition is expected, near 'THEN'.
我將如何得到這個工作?說如果該參數是'活動',然後按照以下標準返回記錄?
作爲旁白...您需要關閉那個'Active'然後聲明的parens。 – DKnight 2011-05-09 15:54:35
添加了關閉的零部件 – davmos 2014-02-26 07:39:33