TSQL- Using CASE in WHERE clause with a < or = sign

后端 未结 2 2050
别跟我提以往
别跟我提以往 2021-01-28 08:46

I am trying to select the IDs based on period and type of account.Each account type would have a different period. I tried the following code but it didnt like the < operator

2条回答
  •  -上瘾入骨i
    2021-01-28 09:38

    You're misunderstanding the case statement. What you have in your THEN clause is what is returned by the CASE statement (like an if... then... statement). The way you have it written, it returns a boolean.

    Try this instead...

    SELECT ID, Period, Type
    FROM Table1
    WHERE Type='ASSET' AND Period < @inputperiod
    UNION
    SELECT ID, Period, Type
    FROM Table1
    WHERE Type='Liability' AND Period BETWEEN @start AND @enddate 
    

提交回复
热议问题