【问题标题】:Bind Output Results to Variable将输出结果绑定到变量
【发布时间】:2015-04-13 00:39:32
【问题描述】:

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

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

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

【问题讨论】:

    标签: output sqldatasource unique-id


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 2015-05-07
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 2020-02-25
      相关资源
      最近更新 更多