情况条件

时间:2017-05-16 13:33:36

标签: sql sql-server tsql sql-server-2012

(case when @InAct = 1 then (pck.packageID = (select pa.packageID  from PakacgeTb pa where (pck.packageID = pa.packageID)

 and 

((cast(pck.expirydate as date) > cast(getdate() as date)) and cast(pck.BalanceVisit as decimal) > cast(0.00 as decimal)))))

我正在尝试使用where case情况我不知道如何使用它。整个代码在where条件之后使用。

2 个答案:

答案 0 :(得分:0)

您可以使用conv = concat . f where f [] = [] f (x:xs) = map (x+) xs : f xs > conv [3,10,5] [13,8,15] > conv [2,5,15,34] [7,17,36,20,39,49] 子句中的复合条件转换CASE表达式,如

WHERE

答案 1 :(得分:0)

Case的简单结构

select 
CASE when ISNULL(pa.[packageID],1) = 1 then 'do something' 
else 'do something' 
end   
from PakacgeTb pa

您必须使用然后作为条件。见下文。

and (CASE when coalesce(@InAct,1) = 1 and pck.packageID in (select 
pa.packageID from PakacgeTb pa) and ((cast(pck.expirydate as date) > 
cast(getdate() as date)) and cast(pck.BalanceVisit as decimal) > cast(0.00 
as decimal))

then 'do something'

else 'this will only execute if when condition does not satisfy'

end