How do you search between two columns using a parameter and a case when statement? SQL Server
Posted
by Kip Birgen
on Stack Overflow
See other posts from Stack Overflow
or by Kip Birgen
Published on 2010-05-11T09:20:17Z
Indexed on
2010/05/11
9:24 UTC
Read the original article
Hit count: 314
I would like to search between to columns in a s query or a table depending on the variable on a paramenter e.g
Declare @SelectAll as interger Set @SelectAll = 1 Declare @Column as interger
Select mt.Column1, mtColumn2 From MyTable as mt Where Case When @SelectAll = 1 Then mt.Column1 IN(@Column) and mt.Column2 (' Selecting all") When @SelectAll = 1 Then mt.Column2 IN(@Column) and mt.Column1 (' Selecting all") End
The purpose of this query is to allow the user to search between the column they choose. Further more the use of parameter is for the purposes of writing reporting services reports.
© Stack Overflow or respective owner