简体   繁体   English

SQL 根据参数从表中排除行

[英]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如果@FY_Ending < 到 2020 年,则取名为 Code 的列

If @FY_Ending is >= 2020 then take the column name Code but drop where LA_Code in (810,811)如果@FY_Ending >= 2020,则取列名称 Code 但将 LA_Code 放在 (810,811) 中的位置

(Note: Code is just a column of different numbers and 2 would like to be excluded from 2020 onwards) (注意:代码只是一列不同的数字,从 2020 年起希望排除 2)

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 sql 应该是这样的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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