[英]SQL exclude rows from table based on parameter
我有一個數據表,並且想根據以下參數創建一個案例:
DECLARE @FY_Ending INT
SET @FY_Ending = 2020
如果@FY_Ending
< 到 2020 年,則取名為 Code 的列
如果@FY_Ending
>= 2020,則取列名稱 Code 但將 LA_Code 放在 (810,811) 中的位置
(注意:代碼只是一列不同的數字,從 2020 年起希望排除 2)
關於寫這篇文章,我會怎么寫?
先感謝您
select code
from your_table
where (@FY_Ending < 2020 and LA_Code in (810,811))
or @FY_Ending >= 2020
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.