0
我在select语句中获取了id的列表。如何通过每个ID循环并打印下面如何遍历ID列表
DECLARE @InventoryID INT
Select @InventoryID = I.InventoryID
From G2owner.LoadSlip L (nolock)
Inner Join G2owner.LoadSlipReleaseOrderMapping LM (nolock) on L.LoadSlipID = LM.LoadSlipID
Inner Join G2owner.LoadSlipDetail LSD (nolock) on LM.LoadSlipReleaseOrdermappingID = LSD.LoadSlipReleaseOrdermappingID
Inner Join G2owner.Inventory I (nolock) on LSD.InventoryID = I.InventoryID
Where LM.ReleaseOrderID = 7156 and L.LoadSlipID = 3014
and L.TerminalID = 3 and I.InventoryEndDate IS NULL and I.TotalNetWeight = 0.0000000
PRINT @InventoryID
是什么让你觉得你需要一个循环?只需使用'Select I.InventoryID From ...'。 –
我需要循环,因为我需要在其他存储过程中的多个位置使用每个invetoryID – user1030181
即使将ID列表转储到临时表,您也应尽量尝试尽量使用基于集合的逻辑。但是,如果你坚持要使用循环,你必须[使用游标](http://stackoverflow.com/questions/11856518/sql-server-2008-request-example-on-creating-a -cursor-to-loop-through-records)来执行你所描述的内容。 –