我要完成從case when
如何在SQL Server的CASE中使用「IN」?
If @chk='Y'
Select * From Table1 Where [email protected]
Else If (@chk='N')
Select * From Table1 Where Column1 In (Select column2 from Table2)
下面我想這可能是這樣的:
Select *
From Table1
Where
Case When @chk='Y' Then
[email protected]
Else
Column1 In (Select column2 from Table2)
End
我知道還有比Case When
其他替代解決方案。但是有可能使用Case when
來做到這一點嗎?
他們是兩個不同的表,是否正確? – mattytommo
Table1和Table2是不同的表。 – Vivek