• halifaxdal (8/18/2014)


    SQLRNNR (8/18/2014)


    halifaxdal (8/18/2014)


    unfortunately CTE is not allowed in this particular staging table creation, and even if it is allowed, 10 million records would be a lengthy dump.:crazy:

    So use a temp table.

    Using that case statement (or a udf) in the group by is a recipe for causing your query to perform terribly.

    Dumping to a temp table will often solve that.

    Sorry I should have mentioned that temp is also not allowed: only "select", no declare, no CTE, no temp, no variables, no ORDER

    And why would you want to handcuff yourself like that?

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events