0

我正在使用 aSQLDataSource将信息插入数据库。在插入的同时,它也会抓取该ID行的

INSERT INTO InkInventory(CodeNumber, InkType, PMS, Color, Description, PoundAvailable, Location, Supplier)
OUTPUT INSERTED.ID 
VALUES (@CodeNumber, @InkType, @PMS, @Color, @Description, @PoundsAvailable, @Location, @Supplier)

当我使用查询生成器时,它可以完美地为我提供输出,但是我如何在后面的代码中引用这些结果,以便在其他地方使用该数字?

4

1 回答 1

0
USE AdventureWorks2012;
GO
--Display the value of LocationID in the last row in the table.
SELECT MAX(LocationID) FROM Production.Location;
GO
INSERT INTO Production.Location (Name, CostRate, Availability, ModifiedDate)
VALUES ('Damaged Goods', 5, 2.5, GETDATE());
GO
SELECT @@IDENTITY AS 'Identity';
GO
--Display the value of LocationID of the newly inserted row.
SELECT MAX(LocationID) FROM Production.Location;
GO
于 2016-01-20T11:53:35.947 回答