例如,假设我有,
create table product
(
ID INT IDENTITY(1,1) NOT NULL,
Name VARCHAR(10)
)
insert into product(Name) values('a')
insert into product(Name) values('b')
insert into product(Name) values('c')
insert into product(Name) values('d')
insert into product(Name) values('e')
create table #tempproduct
(
ID INT IDENTITY(1,1) NOT NULL,
Name VARCHAR(10)
)
declare @OutputAttributesValues table
(
[NewID] INT,
[OldID] INT
)
insert into #tempproduct(Name)
OUTPUT INSERTED.[ID],[ID] INTO @OutputAttributesValues
select [Name] FROM product
请参阅我需要从输出中获取旧 ID 和新 ID。但是这个sql给了我错误“无效的列名'ID'。” http://sqlfiddle.com/#!3/a27b2/1