Here is the data used for the Logic Testing of TSQL Challenge #15. Thanks Brad for helping to build the tricky data.
Table 1
SET NOCOUNT ON DECLARE @Cols TABLE(Col INT); INSERT INTO @Cols VALUES (1); INSERT INTO @Cols VALUES (2); INSERT INTO @Cols VALUES (3); INSERT INTO @Cols VALUES (4); INSERT INTO @Cols VALUES (5); INSERT INTO @Cols VALUES (6); INSERT INTO @Cols VALUES (7); INSERT INTO @Cols VALUES (8); INSERT INTO @Cols VALUES (9); insert into @Cols select 10 union all select 11 union all select 12 union all select 13 union all select 14 union all select 15 union all select 16 union all select 17 union all select 18 union all select 19 union all select 20 union all select -2147483648 union all select 2147483647 SELECT * FROM @Cols /* Col ----------- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 -2147483648 2147483647 */
Table 2
DECLARE @Rows TABLE(Row INT); INSERT INTO @Rows VALUES (100); INSERT INTO @Rows VALUES (104); INSERT INTO @Rows VALUES (101); INSERT INTO @Rows VALUES (99); INSERT INTO @Rows VALUES (77); INSERT INTO @Rows VALUES (20); INSERT INTO @Rows VALUES (10); INSERT INTO @Rows select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9 union all select -1 union all select -2 union all select -3 union all select -4 union all select -5 union all select -6 union all select -7 union all select -8 union all select -9 union all select -2*3*4*5 union all select -6*7*8*9 union all select -2*3*4*5*6*7*8*9 union all select 2*3*4*5 union all select 6*7*8*9 union all select 2*3*4*5*6*7*8*9 union all select -2147483648 union all select 2147483647 SELECT * FROM @Rows /* Row ----------- 100 104 101 99 77 20 10 0 1 2 3 4 5 6 7 8 9 -1 -2 -3 -4 -5 -6 -7 -8 -9 -120 -3024 -362880 120 3024 362880 -2147483648 2147483647 */
Here is the expected output based on the above sample data.
/* Row 1 2 3 4 5 6 7 8 9 ----------- ---- ---- ---- ---- ---- ---- ---- ---- ---- -2147483648 x x x x -362880 x x x x x x x x x -3024 x x x x x x x x -120 x x x x x x x -9 x x x -8 x x x x -7 x x -6 x x x x -5 x x -4 x x x -3 x x -2 x x -1 x 0 x x x x x x x x x 1 x 2 x x 3 x x 4 x x x 5 x x 6 x x x x 7 x x 8 x x x x 9 x x x 10 x x x 20 x x x x 77 x x 99 x x x 100 x x x x 101 x 104 x x x x 120 x x x x x x x 3024 x x x x x x x x 362880 x x x x x x x x x 2147483647 x */