【发布时间】:2019-11-06 13:29:53
【问题描述】:
我收到此错误,但我认为我已经声明了它。谁能告诉我哪里出错了?
DECLARE @ID TABLE(OrderID INT)
INSERT INTO [dbo].[Order](UserID, To_Adress, OrderDate, TravelTime, ItemCount, Status, TotalPrice)
OUTPUT INSERTED.OrderID INTO @ID
VALUES (1, 'BIKINI BOTTOM', '20191030 15:00:00', '20191030 15:35:00', 1, 'InTheMaking', 7.50)
INSERT INTO [dbo].[Order_Product](OrderID, ProductID) VALUES (@ID, 12)
背景:所以基本上我尝试获取我刚刚插入的自动递增 ID 并尝试实现 DECLARE OUTPUT
方法而不是来自 BugFinder 的评论中的 SCOPE_IDENTITY()-way。 Can I get the ID of the data that I just inserted?
【问题讨论】: