Shift Numbers in SQL Server using a CROSS JOIN


use adventureworks2008;
DROP TABLE dbo.Numbers
CREATE TABLE dbo.Numbers (Number INT NOT NULL);
DECLARE @i INT;
SELECT @i = 1;
SET NOCOUNT ON
WHILE @i <= 100000
BEGIN
    INSERT INTO dbo.Numbers(Number) VALUES (@i);
    SELECT @i = @i + 1;
END;
SET NOCOUNT OFF
ALTER TABLE dbo.Numbers ADD CONSTRAINT PK_Numbers PRIMARY KEY CLUSTERED (Number)
SELECT COUNT(*) FROM dbo.Numbers;

use adventureworks2008;
select d.number as theday, s.number as theshift
from dbo.numbers as d cross join dbo.numbers as s
where d.number <= 7
and s.number <= 3
order by theday, theshift;