Working with
- SQL server 2005
- procedures
- parameters
I have a normal query:
select column1, column2
from table1
where column3 in ( select columnb from table2 )
and now I have a filter for example an int
declare @filtertype int /*@filtertype=1 then column3,@filtertype=2 then column2*/
set @filtertype int
i nedd somethings as this
select column1, column2
from table1
where
case when @filtertype=1 then (column3 in (select columnb from table2))
else (column2 in (select columnb from table2))
if you see it, you could see unique change is column3 for column2
I do not want to duplicate my large query like this:
if(@filtertype=1)
begin
first query
end
else
other query
begin
end
Try this: