Может кто-нибудь, пожалуйста, скажите мне, почему это не сработает. Я хочу зациклить внутри цикла .....
BEGIN
SET NOCOUNT ON;
Declare @TempLocations Table (PK int Identity(1,1) not null Primary key, LocationID Int)
Declare @TempItems Table (PK1 int Identity(1,1) not null Primary key, ItemID int)
Declare @TempTable Table (ID Int Identity(1,1), LocationID int, ItemID int)
Declare @MaxLocationID int,
@MaxItemID Int,
@LocationID int,
@ItemID int
-- Load "Can be sold from" Locations into Temp Table
Insert Into @TempLocations (LocationID)
Select LocationID from WMS.Locations
Where CanBeSoldFrom = 'Checked'
Set @MaxItemID = (Select MAX(PK1) From @TempItems)
Set @LocationID = 1
-- Load "IsActive" Items into Temp Table
Insert Into @TempItems (ItemID)
Select ItemID from IMS.ItemDetails
Where IsActive = 'Checked'
Set @MaxLocationID = (Select MAX(PK) From @TempLocations)
Set @ItemID = 1
--Main Code
While @LocationID <= @MaxLocationID
Begin
While @ItemID <= @MaxItemID
Begin
Insert into @TempTable (LocationID, ItemID)
Values (@LocationID, @ItemID)
Set @ItemID = @ItemID + 1
end
Set @LocationID = @LocationID + 1
End
Select * from @TempTable
END
Результат, который я пытаюсь получить, таков:
@ tempTable =
LocationID = 1
ItemID = 1
ItemID = 2
ItemID = 3
ItemID = 4
LocationID = 2
ItemID = 1
ItemID = 2
ItemID = 3
ItemID = 4
и т. Д. ......