with statement

  • Can I use two ddl after with cte statement?

    The first ddl is to use a merget statement to update a column.

    the second ddl is to insert the updated record into another log table.

    Thanks,

  • Being pedantic, you can't use any ddl statements with a cte.

    Without being pedantic and trying to be useful, I assume you want to say DML. However, ctes work only for one statement. You could insert the result of your cte into a temp table and use it for both statements.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks, you are right I mean DML, one update, one insert,

    it looks like using a temp table is a good solution.

  • sqlfriends (1/17/2014)


    Thanks, you are right I mean DML, one update, one insert,

    it looks like using a temp table is a good solution.

    Actually depends what you are attempting to accomplish. Why don't you provide the code you are using and we can see if it needs to be done using a temporary table or not.

  • Have you tried the OUTPUT clause?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Remember, while it has the word "table" in the definition of Common Table Expression, a CTE is nothing but a query. It's not a table. Comparing it to a temp table means you might be under that impression.

    "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

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply