Q:

SELECT SQL table retrieved by an IF statement

Hella all, 
What I want to do is something like that, I will have an SQL table depending on my parameter,
DECLARE @find varchar(30)
SET @find = 'no'

SELECT * FROM
(

    if @find = 'yes'
    (
    SELECT * FROM myTable
    WHERE ID= '5882'
    )
    ELSE
    (
    SELECT * FROM myTable
    WHERE OLD_ID= '5882'
    )   

) X

This is just a simple table that I gave as an example, my real sql query is much more bigger and so I don't think I can use dynamic sql within this query. So I need some other way.

A:

Use the 'searched CASE function' like this:
WHERE
    CASE 
         WHEN @find = 'no' THEN ID
         WHEN @find = 'yes' THEN OLD_ID
         -- put an ELSE clause here
         -- if you want to catch @find not being no or yes
    END 
    = '5882'

