-
-
Save anonymous/78c9724d6e8cdb3397eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE dbo.Final | |
( | |
ID int IDENTITY(1,1) NOT NULL | |
, text1 varchar(50) NOT NULL | |
, text2 varchar(50) NOT NULL | |
, text3 varchar(50) NOT NULL | |
); | |
CREATE TABLE dbo.Chain | |
( | |
ID int NOT NULL | |
); | |
-- Works | |
INSERT INTO | |
dbo.Final | |
( | |
text1 | |
, text2 | |
, text3 | |
) | |
OUTPUT | |
INSERTED.* | |
SELECT | |
D.t1 | |
, D.t2 | |
, D.t3 | |
FROM | |
( | |
VALUES | |
('A', 'B', 'C') | |
, ('D', 'B', 'C') | |
, ('G', 'B', 'C') | |
, ('J', 'B', 'C') | |
) D (t1,t2,t3) | |
-- Comment out the insert portion to generate | |
-- A nested INSERT, UPDATE, DELETE, or MERGE statement is not allowed in a SELECT statement that is not the immediate source of rows for an INSERT statement. | |
INSERT INTO | |
dbo.Chain | |
( | |
ID | |
) | |
SELECT | |
X.ID | |
FROM | |
( | |
INSERT INTO | |
dbo.Final | |
( | |
text1 | |
, text2 | |
, text3 | |
) | |
OUTPUT | |
INSERTED.* | |
SELECT | |
D.t1 | |
, D.t2 | |
, D.t3 | |
FROM | |
( | |
VALUES | |
('A', 'B', 'C') | |
, ('D', 'B', 'C') | |
, ('G', 'B', 'C') | |
, ('J', 'B', 'C') | |
) D (t1,t2,t3) | |
) x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment