我有以下查询:
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'.
我将如何使它工作?说参数是否为“有效”,则返回具有以下条件的记录?
您可以使用另一种方法:
SELECT * FROM dbo.tblOrders o WHERE o.OrderId IN (SELECT [Value] FROM [dbo].[udf_GenerateVarcharTableFromStringList](@OrderId, ',')) AND ((@ActiveInactive = 'Active' AND o.[orderactivedate] > o.[orderinactivedate]) OR (@ActiveInactive = 'Inactive' AND o.[orderactivedate] < o.[orderinactivedate]))