Skip to content

Instantly share code, notes, and snippets.

@Codesleuth
Last active September 22, 2015 08:40
Show Gist options
  • Save Codesleuth/e6eeef30f873d481966d to your computer and use it in GitHub Desktop.
Save Codesleuth/e6eeef30f873d481966d to your computer and use it in GitHub Desktop.
Example of an INSERT, OUTPUT and SELECT transaction
DECLARE @a uniqueidentifier
DECLARE @b uniqueidentifier
SET @a = newid()
SET @b = newid()
DECLARE @t TABLE
(
a uniqueidentifier,
b uniqueidentifier
)
INSERT INTO @t
OUTPUT Inserted.a, Inserted.b
SELECT @a, @b
WHERE NOT EXISTS ( SELECT TOP 1 1 FROM @t WHERE a = @a )
INSERT INTO @t
OUTPUT Inserted.a, Inserted.b
SELECT @a, @b
WHERE NOT EXISTS ( SELECT TOP 1 1 FROM @t WHERE a = @a )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment