简体   繁体   中英

SQL exclude rows from table based on parameter

I have a table of data, and would like to create a case when based on the following parameter:

DECLARE @FY_Ending INT
SET @FY_Ending = 2020

If @FY_Ending is < to 2020 then take the column named Code

If @FY_Ending is >= 2020 then take the column name Code but drop where LA_Code in (810,811)

(Note: Code is just a column of different numbers and 2 would like to be excluded from 2020 onwards)

How would I go about writing this?

Thank you in advance

select code
from your_table
where (@FY_Ending < 2020 and LA_Code in (810,811))
   or @FY_Ending >= 2020 

The sql should look like this

select Code from Table where (@FY_Ending < 2020) or (@FY_Ending >= 2020 and LA_Code in (810,811)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM