sql server - Switch Case in SQL Where Clause -
i want use case when statements inside where clause allow different where criteria depending on specific variable. have idea of how looks like, don't know if it's possible or syntax use.
i used such:
select * table1 case when @var = 1 id = 5 end, case when @var = 2 name = 'bob' end, case when @var = 3 color = 'green' where each instance of @var where condition different. appreciated.
you not need case that:
select * table1 (@var = 1 , id = 5) or (@var = 2 , name = 'bob') or (@var = 3 , color = 'green')
Comments
Post a Comment