我需要在表格中输入一个包含7种类型音高的126个站点的列表。我写的剧本不对,我无法弄清楚原因。
我希望看到的是一列Site_Skey
1,1,1,1,1,1,1和一列PitchType_Skey
1,2,3,4,5, 6,7然后Site_Skey
2,2,2,2,2,2,2和PitchType_Skey
1,2,3,4,5,6,7列需要重复这一点126次。
你能帮忙吗?
当前脚本:
DECLARE @PitchType_Skey INT
DECLARE @Site_Skey INT
SET @PitchType_Skey = 1
SET @Site_Skey = 1
WHILE (@PitchType_Skey <= 882)
WHILE (@Site_Skey <= 882)
BEGIN
INSERT INTO Capacity (PitchType_Skey, Site_Skey)
SELECT (CASE WHEN @PitchType_Skey % 7 = 0 THEN 7 ELSE @PitchType_Skey % 7 END),
(CASE WHEN @Site_Skey % 126 = 0 THEN 126 ELSE @Site_Skey % 126 END)
SET @PitchType_Skey = @PitchType_Skey + 1
SET @Site_Skey = @Site_Skey + 1
END
答案 0 :(得分:0)
非常简单的做法....
DECLARE @PitchType_Skey INT
DECLARE @Site_Skey INT
SET @PitchType_Skey = 1
SET @Site_Skey = 1
WHILE (@Site_Skey < 127)
BEGIN
IF @PitchType_Skey = 8
BEGIN
SET @PitchType_Skey = 1
SET @Site_Skey = @Site_Skey + 1
END
IF (@Site_Skey < 127)
BEGIN
INSERT INTO dbo.Capacity (PitchType_Skey, Site_Skey)
SELECT @PitchType_Skey, @Site_Skey
END
SET @PitchType_Skey = @PitchType_Skey + 1
END