question

Slick84 avatar image
Slick84 asked

Can you use a CTE inside a transaction block?

Hi,

I'd like to know if I'm able to use a CTE inside a transaction block like so:

BEGIN TRANSACTION

WITH CTE .....
SELECT.....etc.

COMMIT TRANSACTION

Any insight will be appreciated.

Thanks,
S

transactioncte
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered

yes you can use a CTE within a transaction, the only point I would make is that you need to inlcude the ';' statement terminator

i.e.

BEGIN TRANSACTION

;WITH CTE .....
SELECT.....etc.

COMMIT TRANSACTION
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image
Matt Whitfield answered

Yes, there's absolutely no reason why not. You may need to make sure the statement before the cte is terminated with a semicolon, but that's about all...

1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Yep, that was it! Thanks.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.