2

I moving from different SQL languages and I want to UPDATE a table and to return some of its columns as below.

Here is how I done it in postgreSQL -

UPDATE account
SET last_login = CURRENT_TIMESTAMP
RETURNING email, created_on, last_login

how do I return certain columns in MS SQL ?

3
  • 4
    Use the OUTPUT clause. This can return both the original and new values in an UPDATE operations Commented Jan 8, 2021 at 10:46
  • @PanagiotisKanavos I tried but I can't seem to find the correct syntax. Commented Jan 8, 2021 at 10:52
  • 1
    Did you check the docs? Examples C through G are UPDATEs with OUTPUT. What did you try? Commented Jan 8, 2021 at 11:15

1 Answer 1

4
UPDATE account
SET last_login = CURRENT_TIMESTAMP
OUTPUT INSERTED.*, DELETED.last_login

sqlfiddle

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.