OK, dette vil give dig det ønskede resultat, men det er tvivlsomt. Jeg vil prøve at forbedre det lidt derefter.
DECLARE @tblCalendar TABLE(
CalendarEntryID INT,
Slot INT
)
DECLARE
@x int, @y int
SET @X = 1 SET @y = 1
WHILE @X <= 100
BEGIN
WHILE @Y <=8 AND @X <= 100--LOOP FOR SLOT COLUMN
BEGIN
INSERT INTO @tblCalendar (CalendarEntryID,Slot)
Values (@x, @y)
SET @y = @y + 1
SET @x = @x + 1
end
SET @y = 1
END
SELECT *
FROM @tblCalendar
En anden tilgang ville være at gøre brug af en IDENTITETSKOLONNE
Noget lignende
DECLARE @tblCalendar TABLE(
CalendarEntryID INT IDENTITY(1,1),
Slot INT
)
DECLARE
@x int, @y int
SET @X = 1 SET @y = 1
WHILE @X <= 100
BEGIN
WHILE @Y <=8 AND @X <= 100--LOOP FOR SLOT COLUMN
BEGIN
INSERT INTO @tblCalendar (Slot)
Values (@y)
SET @y = @y + 1
SET @x = @x + 1
end
SET @y = 1
END
SELECT *
FROM @tblCalendar
Men personligt ville jeg være gået efter
DECLARE @Max INT = 100,
@MaxGroup INT = 8
;WITH Val AS (
SELECT 1 CalendarEntryID
UNION ALL
SELECT CalendarEntryID + 1
FROM Val
WHERE CalendarEntryID + 1 <= @Max
)
SELECT CalendarEntryID,
((CalendarEntryID - 1) % @MaxGroup) + 1 Slot
FROM Val
OPTION (MAXRECURSION 0)