OK, przyniesie to pożądany rezultat, ale jest to wątpliwe. Po tym spróbuję go trochę poprawić.
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
Innym podejściem byłoby skorzystanie z KOLUMNY TOŻSAMOŚCI
Coś jak
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
Ale osobiście wybrałbym
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)