I want to accomplish the following from case when
If @chk='Y'
Select * From Table1 Where Column1=@Value
Else If (@chk='N')
Select * From Table1 Where Column1 In (Select column2 from Table2)
I think it may be something like:
Select *
From Table1
Where
Case When @chk='Y' Then
Column1=@Value
Else
Column1 In (Select column2 from Table2)
End
I know there are alternative solutions other than Case When. But is it possible to do this using Case when?
CASE is an expression that returns a single value. It is not used for control of flow.