• ssssqlguy (4/9/2012)


    You can do what karamaswamy above mentioned; or you can also create an indexed view against these tables (assuming their schema is the same). This way, your queries can hit the view instead of switching between the tables during runtime execution.

    Note that using Dynamic SQL is an expensive SQL operation. You may have to try out these options (dynamic sql, if..else, indexed view) and see which one works best for you.

    Cheers

    I'm assuming in the definition of the view you would add the actual table name the data is coming from so that could be used as part of the filter condition in the where clause, correct?