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

后端 未结 2 2054
别跟我提以往
别跟我提以往 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条回答
  •  佛祖请我去吃肉
    2021-01-28 09:47

    You can't use CASE to swap out arbitrary bits of the query. You would need to use

       SELECT ID, Period, Type 
       FROM TABLE1
       WHERE (Type='ASSET' AND Period < @inputperiod ) 
        OR    (Type='Liability' AND Period BETWEEN @start AND @enddate)
    

提交回复
热议问题