• Sandy (10/29/2007)


    Hey Grant,

    Can you have a look on to my last post..

    I will be happy if you and jeff will have a

    sharp eye on my post.

    Thanks a lot for your reply.

    Cheers!

    Sandy.

    Hey Sandy,

    Don't limit your options, Gail is better at this stuff than I am.

    You need to think about these as different things with different functions. CTE is an extremely neat and clean way to create a multi-use derived table, a temporary view as others defined it. Table variables and temporary tables are methods for persisting data temporarily. Neither directly assists in querying the way a CTE does. Usually they're used when you need to some sort of multi-step manipulation or share data between processes or something along those lines. But again, when the time comes to query the data out of a table variable or temp table, there are very distinct differences in behavior that, depending on the amount of data, makes temp tables perform better than table variables.

    Cheers.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning