My query in Stored procedure looks like this.
insert into a(name) select name from b.
I want to get all the new identity 开发者_如何学运维value from a. How can i do this?
Thanks in advance.
insert into a(name)
OUTPUT INSERTED.IDColumn --this line for >1 row
select name from b.
The OUTPUT Clause
Have a look at OUTPUT Clause (Transact-SQL)
Something like
DECLARE @a TABLE(
ID INT IDENTITY (1,1),
Name VARCHAR(250)
)
DECLARE @b TABLE(
Name VARCHAR(250)
)
INSERT INTO @b SELECT 'a'
INSERT INTO @b SELECT 'b'
INSERT INTO @b SELECT 'c'
INSERT INTO @b SELECT 'd'
INSERT INTO @a(name)
OUTPUT INSERTED.ID
SELECT name FROM @b
精彩评论