6

I have a CTE:

;WITH DeleteTarget AS
(
    ....
)

How do I use this CTE for two delete statements - maybe like:

DELETE FROM [TableA]
WHERE ColumnA IN (SELECT Id FROM DeleteTarget)

DELETE FROM [TableB]
WHERE ColumnB IN (SELECT Name FROM DeleteTarget)
0

1 Answer 1

5

You cannot - a CTE only exists for the one, next statement.

If you need this information that the CTE provides more than once, you need to:

  • store the result set into a table variable or temp table
  • then execute your multiple statements using that table variable / temp table
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.