1

In the code below, the OUTPUT Updated.* fails when executed as-is, but removing the FROM in the UPDATE and replacing it with a static value works fine. Is there a different syntax required when using OUTPUT with an UPDATE FROM?

 USE SCRATCH

 CREATE TABLE Tab1(a char(10))
 CREATE TABLE Tab2(a char(10))
 CREATE TABLE Tab3(a char(10))

 INSERT INTO Tab1(a) values ('a')
 INSERT INTO Tab1(a) values ('a')
 INSERT INTO Tab1(a) values ('a')
 INSERT INTO Tab1(a) values ('a')
 INSERT INTO Tab1(a) values ('a')

 INSERT INTO Tab2(a) values ('a')
 INSERT INTO Tab2(a) values ('a')
 INSERT INTO Tab2(a) values ('a')
 INSERT INTO Tab2(a) values ('a')
 INSERT INTO Tab2(a) values ('a')

 UPDATE T1
 SET T1.a = T2.a
 FROM Tab1 T1 JOIN Tab2 T2 ON T1.a = T2.a
 OUTPUT Updated.*

The error I get is

Msg 102, Level 15, State 1, Line 22
Incorrect syntax near 'OUTPUT'.

1 Answer 1

12

No it's the same syntax

The output still goes immediately after the set.

There is no updated table available though.

UPDATE T1
SET T1.a = T2.a
OUTPUT INSERTED.*,DELETED.*
FROM Tab1 T1 JOIN Tab2 T2 ON T1.a = T2.a

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.