Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TSQL: Return Identity ID using complex UPDATE / INSERT statements #snippet
DECLARE @T TABLE (
cartID INT NOT NULL
)
UPDATE
UserCart
SET
dateModified = GETDATE(),
isGift = 1
OUTPUT
INSERTED.cartID INTO @T
WHERE
userID = 1
IF @@ROWCOUNT = 0
INSERT
INTO UserCart ( userID, isGift)
OUTPUT
INSERTED.cartID INTO @T
VALUES (
1,
1
)
SELECT cartID FROM @T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.