I have a sproc that runs on many different servers. In the sproc I have a select statement that looks like the following.
select *
from my_table
where id = @my_id
and status in (1,3)
However, for one of the databases I need the second part of that where clause to only be for statuses equal to 1. So essentially…
select *
from my_table
where id = @my_id
and status in (1)
I really don’t want to us an if db_name() = 'mydb' statement because the actual select statements are much longer and the code starts to look really inelegant at that point. Is there some way to make the second part of the where clause conditional on the db_name?
Thanks for your help.
Try this: (I think I got your logic right…)
Cause you want it if the status is 1 for any database, but only want the status 3s for the databases that are not that single specified one…