我想根據查詢結果在where子句中選擇變量。我可以在MSSQL的where子句中選擇變量嗎?
Select table1.*, table2.color, table3.type
from table1
inner join table2 on table1.ID=table2.table1Id
inner join table3 on table1.ID=table3.table1Id
where table3.type = @x OR table3.type = @y
| productName | Category | color | type |
| abc | electronics | blue | x |
| abc | electronics | blue | y |
| def | electronics | red | x |
此查詢可以返回重複的結果,因爲產品可以有兩種類型。我想在where子句中選擇變量。例如,我想獲取具有@y類型的產品,但如果產品的@y類型不存在,我想返回@x類型。我不想在示例結果中第一個abc行。你能幫我解答一下嗎?
謝謝。有效。 –