• 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

    Perhaps you meant to say Partitioned View, one which unionizes all of the tables of like schema. This could possibly an indexed as well, but I think we're really talking about a partitioned view.

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho