我在 SQL Server Management Studio 2008 中,我想设置多个 OrderID 以通过此查询运行它们。我听说我必须使用 TempTable,但我不知道如何设置多个表变量。这是我使用的原始查询:
DECLARE @OrderID int
DECLARE @Status int
-- FF nummer
SET @OrderID = 134
-- Huidige status
SET @Status = 4
BEGIN TRANSACTION
UPDATE FF_Task
SET tsk_FK_CurrentStatus = NULL
WHERE (tsk_FK_Order = @OrderID)
UPDATE FF_Order
SET ord_FK_CurrentOrderStatus = NULL
WHERE (ord_PK = @OrderID)
DELETE FROM FF_StatusLog
WHERE (stl_PK IN
(SELECT TOP (1) FF_StatusLog_1.stl_PK
FROM FF_StatusLog AS FF_StatusLog_1 INNER JOIN
FF_Task ON FF_StatusLog_1.stl_FK_Task = FF_Task.tsk_PK
WHERE (FF_Task.tsk_FK_Order = @OrderID)
ORDER BY FF_StatusLog_1.stl_PK DESC))
DELETE
FROM FF_OrderStatusLog
WHERE (osl_Status = @Status) AND (osl_FK_Order = @OrderID)
UPDATE FF_Task
SET
tsk_FK_CurrentStatus = (SELECT TOP (1) FF_StatusLog_1.stl_PK
FROM FF_StatusLog AS FF_StatusLog_1 INNER JOIN
FF_Task ON FF_StatusLog_1.stl_FK_Task = FF_Task.tsk_PK
WHERE (FF_Task.tsk_FK_Order = @OrderID)
ORDER BY FF_StatusLog_1.stl_PK DESC)
WHERE (tsk_FK_Order = @OrderID)
UPDATE FF_Order
SET ord_FK_CurrentOrderStatus = (SELECT TOP 1 osl_Status FROM
FF_OrderStatusLog WHERE (osl_FK_Order = @OrderID) ORDER BY osl_CreationDateTime DESC)
WHERE (ord_PK = @OrderID)
COMMIT TRANSACTION
谢谢你。