0

我需要在表格中输入一个包含 7 种间距的 126 个站点的列表。我写的脚本不正确,我不知道为什么。

我想看到的是1、1、1、1、1、1、1Site_Skey的列和PitchType_Skey1、2、3、4、5、6、7 的列,然后是Site_Skey2、2、2、2、2 ,2,2 和一列PitchType_Skey1,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
4

1 回答 1

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
于 2013-02-12T12:45:40.547 回答