March 11, 2010 at 12:49 pm
Well congratulations indeed Mister Magoo on realizing THE TRILLION!
It's the theme of the day!
March 11, 2010 at 1:23 pm
Thanks steve, and as for themes, you mention queries looking like skyscrapers.....
Attached is my execution plan - looks amazing like a chef's knife - perfect for slicing through the data....:-P
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
March 11, 2010 at 1:42 pm
Whacky man!:crazy:
Is FIZZBUZZ becoming an art form?
March 11, 2010 at 2:07 pm
It could be me, but the execution plan for the UNPIVOT solution still looks a lot like the execution plan of the CROSS JOIN/multiple UNION ALL solution. I'd be interested if anyone could explain why the UNPIVOT seems to work faster than the CROSS JOIN, if that seems to be the concensus out there.
March 11, 2010 at 2:31 pm
Lynn Pettis (3/11/2010)
It could be me, but the execution plan for the UNPIVOT solution still looks a lot like the execution plan of the CROSS JOIN/multiple UNION ALL solution. I'd be interested if anyone could explain why the UNPIVOT seems to work faster than the CROSS JOIN, if that seems to be the concensus out there.
I have tried a few variations of the different methods here and can't say I have seen any reliably measurable difference between them.
The only two TRILLIONS I have seen reported here are of the same order of performance 65-70hours but on different hardware - one using union/cross join/views - the other I think was unpivots (which i believe are actually the same as cross apply or at least very similar)/cross joins. This is harldy enough evidence to draw any conclusions, It might be interesting to write a test harness that generates the various types of solution and plays with the parameters of those (e.g. more columns/unpivots ) to take some more measurements.....
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
March 11, 2010 at 2:51 pm
If you haven't tried this already Mister Magoo, it would be interesting if you were to create your base table using UNPIVOT rather than 32 UNION SELECT statements and see if you notice a measurable improvement. My experience is that UNPIVOT can benefit from using essentially a SINGLE SELECT statement to achieve the same result as multiple UNION SELECTS. This was also the ethos first suggested in the Gianluca Sartori version of creating a base table using UNPIVOT.
March 13, 2010 at 3:52 am
THE TRILLION Revisited
20 UNPIVOT/Million Row Base Table/Single Cross Join Variation
61 hours 58 minutes
Data from sys.dm_exec_query_stats (times are in microseconds)
total_elapsed_time223,100,308,594
total_worker_time 222,967,219,785
total_physical_reads 0
total_logical_reads 0
So folks, do you think THE SKYSCRAPER can beat this?
--20 Unpivots on a 2 column block release over 1 million rows in the base table
--A single cross join then yields over 1 trillion rows
WITH cte1 AS
(
SELECT A FROM
(
SELECT
1 AS A1,1 AS A2,
1 AS B1,1 AS B2,
1 AS C1,1 AS C2,
1 AS D1,1 AS D2,
1 AS E1,1 AS E2,
1 AS F1,1 AS F2,
1 AS G1,1 AS G2,
1 AS H1,1 AS H2,
1 AS I1,1 AS I2,
1 AS J1,1 AS J2,
1 AS AA1,1 AS AA2,
1 AS BB1,1 AS BB2,
1 AS CC1,1 AS CC2,
1 AS DD1,1 AS DD2,
1 AS EE1,1 AS EE2,
1 AS FF1,1 AS FF2,
1 AS GG1,1 AS GG2,
1 AS HH1,1 AS HH2,
1 AS II1,1 AS II2,
1 AS JJ1,1 AS JJ2
) AS Z
UNPIVOT (A FOR O IN (A1,A2)) AS Z
UNPIVOT (B FOR P IN (B1,B2)) AS Z
UNPIVOT (C FOR Q IN (C1,C2)) AS Z
UNPIVOT (D FOR R IN (D1,D2)) AS Z
UNPIVOT (E FOR S IN (E1,E2)) AS Z
UNPIVOT (F FOR T IN (F1,F2)) AS Z
UNPIVOT (G FOR U IN (G1,G2)) AS Z
UNPIVOT (H FOR V IN (H1,H2)) AS Z
UNPIVOT (I FOR W IN (I1,I2)) AS Z
UNPIVOT (J FOR X IN (J1,J2)) AS Z
UNPIVOT (AA FOR OO IN (AA1,AA2)) AS Z
UNPIVOT (BB FOR PP IN (BB1,BB2)) AS Z
UNPIVOT (CC FOR QQ IN (CC1,CC2)) AS Z
UNPIVOT (DD FOR RR IN (DD1,DD2)) AS Z
UNPIVOT (EE FOR SS IN (EE1,EE2)) AS Z
UNPIVOT (FF FOR TT IN (FF1,FF2)) AS Z
UNPIVOT (GG FOR UU IN (GG1,GG2)) AS Z
UNPIVOT (HH FOR VV IN (HH1,HH2)) AS Z
UNPIVOT (II FOR WW IN (II1,II2)) AS Z
UNPIVOT (JJ FOR XX IN (JJ1,JJ2)) AS Z
) --1,048,576 rows
,
cte2 AS
(
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS row FROM cte1
CROSS JOIN cte1 AS T2
) --1,099,511,627,776 rows
SELECT COUNT_BIG(ALL CASE
WHEN row%15 = 0 THEN 'FIZZBUZZ'
WHEN row%5 = 0 THEN 'BUZZ'
WHEN row%3 = 0 THEN 'FIZZ'
ELSE CAST(row AS VARCHAR(14))
END)
FROM cte2 WHERE row < 1000000000001 --set limit to 1 trillion
March 14, 2010 at 4:41 am
CROSS APPLY Variation
Do you think this might be a contender?
WITH cte1 AS
(
SELECT
1 AS A1 UNION ALL SELECT 1
)
,
cte2 AS
(
SELECT A1 FROM cte1 CROSS APPLY
(
SELECT A1 as row UNION ALL SELECT A1 FROM cte1
) AS Z
)
,
cte3 AS
(
SELECT A1 FROM cte2 CROSS APPLY
(
SELECT A1 as row FROM cte2
) AS Z
)
,
cte4 AS
(
SELECT A1 FROM cte3 CROSS APPLY
(
SELECT A1 as row FROM cte3
) AS Z
)
,
cte5 AS
(
SELECT A1 FROM cte4 CROSS APPLY
(
SELECT A1 as row FROM cte4
) AS Z
) --1,679,616 rows
,
cte6 AS
(
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS row FROM cte5
CROSS APPLY (SELECT TOP 654621 A1 FROM cte5) AS T2
) --1,099,511,905,536 rows
SELECT
COUNT_BIG(ALL
CASE
WHEN row%15 = 0 THEN 'FIZZBUZZ'
WHEN row%5 = 0 THEN 'BUZZ'
WHEN row%3 = 0 THEN 'FIZZ'
ELSE CAST(row AS VARCHAR(14))
END
)
FROM cte6 WHERE row < 1000000000001 --set limit to 1 trillion
March 15, 2010 at 1:56 am
THE TRILLION
CREATE VIEW [dbo].[V1] AS
SELECT ROW_NUMBER() OVER(ORDER BY @@SPID) AS ID
FROM
(VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) A(A) ,
(VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) B(A) ,
(VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) C(A) ,
(VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) D(A) ,
(VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) E(A)
GO
select COUNT_BIG(
CASE WHEN ID % 3 = 0 THEN
CASE WHEN ID % 5 = 0 THEN 'FizzBuzz' ELSE 'Fizz' END
WHEN ID % 5 = 0 THEN 'Buzz'
ELSE CONVERT(VARCHAR(14),ID)
END)
from V1
where ID<=1000000000000
That is 4 sets of 512 rows plus a bit more - using sql2008+ specific syntax of multiple values.
For some reason 512 seems to be among the better performing quantities.
If it scales as I hope it should, this should complete the TRILLION in just under 48 hours....let's see...
(I decided to use dynamic sql to test and find "good" values for the width and height of this query - I wish there was some way of calculating it with maths though!)
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
March 15, 2010 at 3:21 am
Wow Mister Magoo, that ROW CONSTRUCTOR syntax is certainly a lot more friendly than UNPIVOT. Seeing your script, I just had to create the UNPIVOT equivalent which is a bit of a monster! I have tested this at the 4 billion limit and it performs very poorly. It looks as if maybe tall and thin is good for multiple UNPIVOTS whereas short and fat is good for the ROW CONSTRUCTOR. Who would have thought that eh? BTW I hope you appreciate this one. It took me ages to type it out!
WITH cte1 AS
(
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS row FROM
(
SELECT
1 AS A1,1 AS A2,1 AS A3,1 AS A4,1 AS A5,1 AS A6,1 AS A7,1 AS A8,1 AS A9,1 AS A10,1 AS A11,1 AS A12,1 AS A13,1 AS A14,1 AS A15,1 AS A16,
1 AS A17,1 AS A18,1 AS A19,1 AS A20,1 AS A21,1 AS A22,1 AS A23,1 AS A24,1 AS A25,1 AS A26,1 AS A27,1 AS A28,1 AS A29,1 AS A30,1 AS A31,1 AS A32,
1 AS A33,1 AS A34,1 AS A35,1 AS A36,1 AS A37,1 AS A38,1 AS A39,1 AS A40,1 AS A41,1 AS A42,1 AS A43,1 AS A44,1 AS A45,1 AS A46,1 AS A47,1 AS A48,
1 AS A49,1 AS A50,1 AS A51,1 AS A52,1 AS A53,1 AS A54,1 AS A55,1 AS A56,1 AS A57,1 AS A58,1 AS A59,1 AS A60,1 AS A61,1 AS A62,1 AS A63,1 AS A64,
1 AS A65,1 AS A66,1 AS A67,1 AS A68,1 AS A69,1 AS A70,1 AS A71,1 AS A72,1 AS A73,1 AS A74,1 AS A75,1 AS A76,1 AS A77,1 AS A78,1 AS A79,1 AS A80,
1 AS A81,1 AS A82,1 AS A83,1 AS A84,1 AS A85,1 AS A86,1 AS A87,1 AS A88,1 AS A89,1 AS A90,1 AS A91,1 AS A92,1 AS A93,1 AS A94,1 AS A95,1 AS A96,
1 AS A97,1 AS A98,1 AS A99,1 AS A100,1 AS A101,1 AS A102,1 AS A103,1 AS A104,1 AS A105,1 AS A106,1 AS A107,1 AS A108,1 AS A109,1 AS A110,1 AS A111,1 AS A112,
1 AS A113,1 AS A114,1 AS A115,1 AS A116,1 AS A117,1 AS A118,1 AS A119,1 AS A120,1 AS A121,1 AS A122,1 AS A123,1 AS A124,1 AS A125,1 AS A126,1 AS A127,1 AS A128,
1 AS A129,1 AS A130,1 AS A131,1 AS A132,1 AS A133,1 AS A134,1 AS A135,1 AS A136,1 AS A137,1 AS A138,1 AS A139,1 AS A140,1 AS A141,1 AS A142,1 AS A143,1 AS A144,
1 AS A145,1 AS A146,1 AS A147,1 AS A148,1 AS A149,1 AS A150,1 AS A151,1 AS A152,1 AS A153,1 AS A154,1 AS A155,1 AS A156,1 AS A157,1 AS A158,1 AS A159,1 AS A160,
1 AS A161,1 AS A162,1 AS A163,1 AS A164,1 AS A165,1 AS A166,1 AS A167,1 AS A168,1 AS A169,1 AS A170,1 AS A171,1 AS A172,1 AS A173,1 AS A174,1 AS A175,1 AS A176,
1 AS A177,1 AS A178,1 AS A179,1 AS A180,1 AS A181,1 AS A182,1 AS A183,1 AS A184,1 AS A185,1 AS A186,1 AS A187,1 AS A188,1 AS A189,1 AS A190,1 AS A191,1 AS A192,
1 AS A193,1 AS A194,1 AS A195,1 AS A196,1 AS A197,1 AS A198,1 AS A199,1 AS A200,1 AS A201,1 AS A202,1 AS A203,1 AS A204,1 AS A205,1 AS A206,1 AS A207,1 AS A208,
1 AS A209,1 AS A210,1 AS A211,1 AS A212,1 AS A213,1 AS A214,1 AS A215,1 AS A216,1 AS A217,1 AS A218,1 AS A219,1 AS A220,1 AS A221,1 AS A222,1 AS A223,1 AS A224,
1 AS A225,1 AS A226,1 AS A227,1 AS A228,1 AS A229,1 AS A230,1 AS A231,1 AS A232,1 AS A233,1 AS A234,1 AS A235,1 AS A236,1 AS A237,1 AS A238,1 AS A239,1 AS A240,
1 AS A241,1 AS A242,1 AS A243,1 AS A244,1 AS A245,1 AS A246,1 AS A247,1 AS A248,1 AS A249,1 AS A250,1 AS A251,1 AS A252,1 AS A253,1 AS A254,1 AS A255,1 AS A256,
1 AS A257,1 AS A258,1 AS A259,1 AS A260,1 AS A261,1 AS A262,1 AS A263,1 AS A264,1 AS A265,1 AS A266,1 AS A267,1 AS A268,1 AS A269,1 AS A270,1 AS A271,1 AS A272,
1 AS A273,1 AS A274,1 AS A275,1 AS A276,1 AS A277,1 AS A278,1 AS A279,1 AS A280,1 AS A281,1 AS A282,1 AS A283,1 AS A284,1 AS A285,1 AS A286,1 AS A287,1 AS A288,
1 AS A289,1 AS A290,1 AS A291,1 AS A292,1 AS A293,1 AS A294,1 AS A295,1 AS A296,1 AS A297,1 AS A298,1 AS A299,1 AS A300,1 AS A301,1 AS A302,1 AS A303,1 AS A304,
1 AS A305,1 AS A306,1 AS A307,1 AS A308,1 AS A309,1 AS A310,1 AS A311,1 AS A312,1 AS A313,1 AS A314,1 AS A315,1 AS A316,1 AS A317,1 AS A318,1 AS A319,1 AS A320,
1 AS A321,1 AS A322,1 AS A323,1 AS A324,1 AS A325,1 AS A326,1 AS A327,1 AS A328,1 AS A329,1 AS A330,1 AS A331,1 AS A332,1 AS A333,1 AS A334,1 AS A335,1 AS A336,
1 AS A337,1 AS A338,1 AS A339,1 AS A340,1 AS A341,1 AS A342,1 AS A343,1 AS A344,1 AS A345,1 AS A346,1 AS A347,1 AS A348,1 AS A349,1 AS A350,1 AS A351,1 AS A352,
1 AS A353,1 AS A354,1 AS A355,1 AS A356,1 AS A357,1 AS A358,1 AS A359,1 AS A360,1 AS A361,1 AS A362,1 AS A363,1 AS A364,1 AS A365,1 AS A366,1 AS A367,1 AS A368,
1 AS A369,1 AS A370,1 AS A371,1 AS A372,1 AS A373,1 AS A374,1 AS A375,1 AS A376,1 AS A377,1 AS A378,1 AS A379,1 AS A380,1 AS A381,1 AS A382,1 AS A383,1 AS A384,
1 AS A385,1 AS A386,1 AS A387,1 AS A388,1 AS A389,1 AS A390,1 AS A391,1 AS A392,1 AS A393,1 AS A394,1 AS A395,1 AS A396,1 AS A397,1 AS A398,1 AS A399,1 AS A400,
1 AS A401,1 AS A402,1 AS A403,1 AS A404,1 AS A405,1 AS A406,1 AS A407,1 AS A408,1 AS A409,1 AS A410,1 AS A411,1 AS A412,1 AS A413,1 AS A414,1 AS A415,1 AS A416,
1 AS A417,1 AS A418,1 AS A419,1 AS A420,1 AS A421,1 AS A422,1 AS A423,1 AS A424,1 AS A425,1 AS A426,1 AS A427,1 AS A428,1 AS A429,1 AS A430,1 AS A431,1 AS A432,
1 AS A433,1 AS A434,1 AS A435,1 AS A436,1 AS A437,1 AS A438,1 AS A439,1 AS A440,1 AS A441,1 AS A442,1 AS A443,1 AS A444,1 AS A445,1 AS A446,1 AS A447,1 AS A448,
1 AS A449,1 AS A450,1 AS A451,1 AS A452,1 AS A453,1 AS A454,1 AS A455,1 AS A456,1 AS A457,1 AS A458,1 AS A459,1 AS A460,1 AS A461,1 AS A462,1 AS A463,1 AS A464,
1 AS A465,1 AS A466,1 AS A467,1 AS A468,1 AS A469,1 AS A470,1 AS A471,1 AS A472,1 AS A473,1 AS A474,1 AS A475,1 AS A476,1 AS A477,1 AS A478,1 AS A479,1 AS A480,
1 AS A481,1 AS A482,1 AS A483,1 AS A484,1 AS A485,1 AS A486,1 AS A487,1 AS A488,1 AS A489,1 AS A490,1 AS A491,1 AS A492,1 AS A493,1 AS A494,1 AS A495,1 AS A496,
1 AS A497,1 AS A498,1 AS A499,1 AS A500,1 AS A501,1 AS A502,1 AS A503,1 AS A504,1 AS A505,1 AS A506,1 AS A507,1 AS A508,1 AS A509,1 AS A510,1 AS A511,1 AS A512,
1 AS B1,1 AS B2,1 AS B3,1 AS B4,1 AS B5,1 AS B6,1 AS B7,1 AS B8,1 AS B9,1 AS B10,1 AS B11,1 AS B12,1 AS B13,1 AS B14,1 AS B15,1 AS B16,
1 AS B17,1 AS B18,1 AS B19,1 AS B20,1 AS B21,1 AS B22,1 AS B23,1 AS B24,1 AS B25,1 AS B26,1 AS B27,1 AS B28,1 AS B29,1 AS B30,1 AS B31,1 AS B32,
1 AS B33,1 AS B34,1 AS B35,1 AS B36,1 AS B37,1 AS B38,1 AS B39,1 AS B40,1 AS B41,1 AS B42,1 AS B43,1 AS B44,1 AS B45,1 AS B46,1 AS B47,1 AS B48,
1 AS B49,1 AS B50,1 AS B51,1 AS B52,1 AS B53,1 AS B54,1 AS B55,1 AS B56,1 AS B57,1 AS B58,1 AS B59,1 AS B60,1 AS B61,1 AS B62,1 AS B63,1 AS B64,
1 AS B65,1 AS B66,1 AS B67,1 AS B68,1 AS B69,1 AS B70,1 AS B71,1 AS B72,1 AS B73,1 AS B74,1 AS B75,1 AS B76,1 AS B77,1 AS B78,1 AS B79,1 AS B80,
1 AS B81,1 AS B82,1 AS B83,1 AS B84,1 AS B85,1 AS B86,1 AS B87,1 AS B88,1 AS B89,1 AS B90,1 AS B91,1 AS B92,1 AS B93,1 AS B94,1 AS B95,1 AS B96,
1 AS B97,1 AS B98,1 AS B99,1 AS B100,1 AS B101,1 AS B102,1 AS B103,1 AS B104,1 AS B105,1 AS B106,1 AS B107,1 AS B108,1 AS B109,1 AS B110,1 AS B111,1 AS B112,
1 AS B113,1 AS B114,1 AS B115,1 AS B116,1 AS B117,1 AS B118,1 AS B119,1 AS B120,1 AS B121,1 AS B122,1 AS B123,1 AS B124,1 AS B125,1 AS B126,1 AS B127,1 AS B128,
1 AS B129,1 AS B130,1 AS B131,1 AS B132,1 AS B133,1 AS B134,1 AS B135,1 AS B136,1 AS B137,1 AS B138,1 AS B139,1 AS B140,1 AS B141,1 AS B142,1 AS B143,1 AS B144,
1 AS B145,1 AS B146,1 AS B147,1 AS B148,1 AS B149,1 AS B150,1 AS B151,1 AS B152,1 AS B153,1 AS B154,1 AS B155,1 AS B156,1 AS B157,1 AS B158,1 AS B159,1 AS B160,
1 AS B161,1 AS B162,1 AS B163,1 AS B164,1 AS B165,1 AS B166,1 AS B167,1 AS B168,1 AS B169,1 AS B170,1 AS B171,1 AS B172,1 AS B173,1 AS B174,1 AS B175,1 AS B176,
1 AS B177,1 AS B178,1 AS B179,1 AS B180,1 AS B181,1 AS B182,1 AS B183,1 AS B184,1 AS B185,1 AS B186,1 AS B187,1 AS B188,1 AS B189,1 AS B190,1 AS B191,1 AS B192,
1 AS B193,1 AS B194,1 AS B195,1 AS B196,1 AS B197,1 AS B198,1 AS B199,1 AS B200,1 AS B201,1 AS B202,1 AS B203,1 AS B204,1 AS B205,1 AS B206,1 AS B207,1 AS B208,
1 AS B209,1 AS B210,1 AS B211,1 AS B212,1 AS B213,1 AS B214,1 AS B215,1 AS B216,1 AS B217,1 AS B218,1 AS B219,1 AS B220,1 AS B221,1 AS B222,1 AS B223,1 AS B224,
1 AS B225,1 AS B226,1 AS B227,1 AS B228,1 AS B229,1 AS B230,1 AS B231,1 AS B232,1 AS B233,1 AS B234,1 AS B235,1 AS B236,1 AS B237,1 AS B238,1 AS B239,1 AS B240,
1 AS B241,1 AS B242,1 AS B243,1 AS B244,1 AS B245,1 AS B246,1 AS B247,1 AS B248,1 AS B249,1 AS B250,1 AS B251,1 AS B252,1 AS B253,1 AS B254,1 AS B255,1 AS B256,
1 AS B257,1 AS B258,1 AS B259,1 AS B260,1 AS B261,1 AS B262,1 AS B263,1 AS B264,1 AS B265,1 AS B266,1 AS B267,1 AS B268,1 AS B269,1 AS B270,1 AS B271,1 AS B272,
1 AS B273,1 AS B274,1 AS B275,1 AS B276,1 AS B277,1 AS B278,1 AS B279,1 AS B280,1 AS B281,1 AS B282,1 AS B283,1 AS B284,1 AS B285,1 AS B286,1 AS B287,1 AS B288,
1 AS B289,1 AS B290,1 AS B291,1 AS B292,1 AS B293,1 AS B294,1 AS B295,1 AS B296,1 AS B297,1 AS B298,1 AS B299,1 AS B300,1 AS B301,1 AS B302,1 AS B303,1 AS B304,
1 AS B305,1 AS B306,1 AS B307,1 AS B308,1 AS B309,1 AS B310,1 AS B311,1 AS B312,1 AS B313,1 AS B314,1 AS B315,1 AS B316,1 AS B317,1 AS B318,1 AS B319,1 AS B320,
1 AS B321,1 AS B322,1 AS B323,1 AS B324,1 AS B325,1 AS B326,1 AS B327,1 AS B328,1 AS B329,1 AS B330,1 AS B331,1 AS B332,1 AS B333,1 AS B334,1 AS B335,1 AS B336,
1 AS B337,1 AS B338,1 AS B339,1 AS B340,1 AS B341,1 AS B342,1 AS B343,1 AS B344,1 AS B345,1 AS B346,1 AS B347,1 AS B348,1 AS B349,1 AS B350,1 AS B351,1 AS B352,
1 AS B353,1 AS B354,1 AS B355,1 AS B356,1 AS B357,1 AS B358,1 AS B359,1 AS B360,1 AS B361,1 AS B362,1 AS B363,1 AS B364,1 AS B365,1 AS B366,1 AS B367,1 AS B368,
1 AS B369,1 AS B370,1 AS B371,1 AS B372,1 AS B373,1 AS B374,1 AS B375,1 AS B376,1 AS B377,1 AS B378,1 AS B379,1 AS B380,1 AS B381,1 AS B382,1 AS B383,1 AS B384,
1 AS B385,1 AS B386,1 AS B387,1 AS B388,1 AS B389,1 AS B390,1 AS B391,1 AS B392,1 AS B393,1 AS B394,1 AS B395,1 AS B396,1 AS B397,1 AS B398,1 AS B399,1 AS B400,
1 AS B401,1 AS B402,1 AS B403,1 AS B404,1 AS B405,1 AS B406,1 AS B407,1 AS B408,1 AS B409,1 AS B410,1 AS B411,1 AS B412,1 AS B413,1 AS B414,1 AS B415,1 AS B416,
1 AS B417,1 AS B418,1 AS B419,1 AS B420,1 AS B421,1 AS B422,1 AS B423,1 AS B424,1 AS B425,1 AS B426,1 AS B427,1 AS B428,1 AS B429,1 AS B430,1 AS B431,1 AS B432,
1 AS B433,1 AS B434,1 AS B435,1 AS B436,1 AS B437,1 AS B438,1 AS B439,1 AS B440,1 AS B441,1 AS B442,1 AS B443,1 AS B444,1 AS B445,1 AS B446,1 AS B447,1 AS B448,
1 AS B449,1 AS B450,1 AS B451,1 AS B452,1 AS B453,1 AS B454,1 AS B455,1 AS B456,1 AS B457,1 AS B458,1 AS B459,1 AS B460,1 AS B461,1 AS B462,1 AS B463,1 AS B464,
1 AS B465,1 AS B466,1 AS B467,1 AS B468,1 AS B469,1 AS B470,1 AS B471,1 AS B472,1 AS B473,1 AS B474,1 AS B475,1 AS B476,1 AS B477,1 AS B478,1 AS B479,1 AS B480,
1 AS B481,1 AS B482,1 AS B483,1 AS B484,1 AS B485,1 AS B486,1 AS B487,1 AS B488,1 AS B489,1 AS B490,1 AS B491,1 AS B492,1 AS B493,1 AS B494,1 AS B495,1 AS B496,
1 AS B497,1 AS B498,1 AS B499,1 AS B500,1 AS B501,1 AS B502,1 AS B503,1 AS B504,1 AS B505,1 AS B506,1 AS B507,1 AS B508,1 AS B509,1 AS B510,1 AS B511,1 AS B512,
1 AS C1,1 AS C2,1 AS C3,1 AS C4,1 AS C5,1 AS C6,1 AS C7,1 AS C8,1 AS C9,1 AS C10,1 AS C11,1 AS C12,1 AS C13,1 AS C14,1 AS C15,1 AS C16,
1 AS C17,1 AS C18,1 AS C19,1 AS C20,1 AS C21,1 AS C22,1 AS C23,1 AS C24,1 AS C25,1 AS C26,1 AS C27,1 AS C28,1 AS C29,1 AS C30,1 AS C31,1 AS C32,
1 AS C33,1 AS C34,1 AS C35,1 AS C36,1 AS C37,1 AS C38,1 AS C39,1 AS C40,1 AS C41,1 AS C42,1 AS C43,1 AS C44,1 AS C45,1 AS C46,1 AS C47,1 AS C48,
1 AS C49,1 AS C50,1 AS C51,1 AS C52,1 AS C53,1 AS C54,1 AS C55,1 AS C56,1 AS C57,1 AS C58,1 AS C59,1 AS C60,1 AS C61,1 AS C62,1 AS C63,1 AS C64,
1 AS C65,1 AS C66,1 AS C67,1 AS C68,1 AS C69,1 AS C70,1 AS C71,1 AS C72,1 AS C73,1 AS C74,1 AS C75,1 AS C76,1 AS C77,1 AS C78,1 AS C79,1 AS C80,
1 AS C81,1 AS C82,1 AS C83,1 AS C84,1 AS C85,1 AS C86,1 AS C87,1 AS C88,1 AS C89,1 AS C90,1 AS C91,1 AS C92,1 AS C93,1 AS C94,1 AS C95,1 AS C96,
1 AS C97,1 AS C98,1 AS C99,1 AS C100,1 AS C101,1 AS C102,1 AS C103,1 AS C104,1 AS C105,1 AS C106,1 AS C107,1 AS C108,1 AS C109,1 AS C110,1 AS C111,1 AS C112,
1 AS C113,1 AS C114,1 AS C115,1 AS C116,1 AS C117,1 AS C118,1 AS C119,1 AS C120,1 AS C121,1 AS C122,1 AS C123,1 AS C124,1 AS C125,1 AS C126,1 AS C127,1 AS C128,
1 AS C129,1 AS C130,1 AS C131,1 AS C132,1 AS C133,1 AS C134,1 AS C135,1 AS C136,1 AS C137,1 AS C138,1 AS C139,1 AS C140,1 AS C141,1 AS C142,1 AS C143,1 AS C144,
1 AS C145,1 AS C146,1 AS C147,1 AS C148,1 AS C149,1 AS C150,1 AS C151,1 AS C152,1 AS C153,1 AS C154,1 AS C155,1 AS C156,1 AS C157,1 AS C158,1 AS C159,1 AS C160,
1 AS C161,1 AS C162,1 AS C163,1 AS C164,1 AS C165,1 AS C166,1 AS C167,1 AS C168,1 AS C169,1 AS C170,1 AS C171,1 AS C172,1 AS C173,1 AS C174,1 AS C175,1 AS C176,
1 AS C177,1 AS C178,1 AS C179,1 AS C180,1 AS C181,1 AS C182,1 AS C183,1 AS C184,1 AS C185,1 AS C186,1 AS C187,1 AS C188,1 AS C189,1 AS C190,1 AS C191,1 AS C192,
1 AS C193,1 AS C194,1 AS C195,1 AS C196,1 AS C197,1 AS C198,1 AS C199,1 AS C200,1 AS C201,1 AS C202,1 AS C203,1 AS C204,1 AS C205,1 AS C206,1 AS C207,1 AS C208,
1 AS C209,1 AS C210,1 AS C211,1 AS C212,1 AS C213,1 AS C214,1 AS C215,1 AS C216,1 AS C217,1 AS C218,1 AS C219,1 AS C220,1 AS C221,1 AS C222,1 AS C223,1 AS C224,
1 AS C225,1 AS C226,1 AS C227,1 AS C228,1 AS C229,1 AS C230,1 AS C231,1 AS C232,1 AS C233,1 AS C234,1 AS C235,1 AS C236,1 AS C237,1 AS C238,1 AS C239,1 AS C240,
1 AS C241,1 AS C242,1 AS C243,1 AS C244,1 AS C245,1 AS C246,1 AS C247,1 AS C248,1 AS C249,1 AS C250,1 AS C251,1 AS C252,1 AS C253,1 AS C254,1 AS C255,1 AS C256,
1 AS C257,1 AS C258,1 AS C259,1 AS C260,1 AS C261,1 AS C262,1 AS C263,1 AS C264,1 AS C265,1 AS C266,1 AS C267,1 AS C268,1 AS C269,1 AS C270,1 AS C271,1 AS C272,
1 AS C273,1 AS C274,1 AS C275,1 AS C276,1 AS C277,1 AS C278,1 AS C279,1 AS C280,1 AS C281,1 AS C282,1 AS C283,1 AS C284,1 AS C285,1 AS C286,1 AS C287,1 AS C288,
1 AS C289,1 AS C290,1 AS C291,1 AS C292,1 AS C293,1 AS C294,1 AS C295,1 AS C296,1 AS C297,1 AS C298,1 AS C299,1 AS C300,1 AS C301,1 AS C302,1 AS C303,1 AS C304,
1 AS C305,1 AS C306,1 AS C307,1 AS C308,1 AS C309,1 AS C310,1 AS C311,1 AS C312,1 AS C313,1 AS C314,1 AS C315,1 AS C316,1 AS C317,1 AS C318,1 AS C319,1 AS C320,
1 AS C321,1 AS C322,1 AS C323,1 AS C324,1 AS C325,1 AS C326,1 AS C327,1 AS C328,1 AS C329,1 AS C330,1 AS C331,1 AS C332,1 AS C333,1 AS C334,1 AS C335,1 AS C336,
1 AS C337,1 AS C338,1 AS C339,1 AS C340,1 AS C341,1 AS C342,1 AS C343,1 AS C344,1 AS C345,1 AS C346,1 AS C347,1 AS C348,1 AS C349,1 AS C350,1 AS C351,1 AS C352,
1 AS C353,1 AS C354,1 AS C355,1 AS C356,1 AS C357,1 AS C358,1 AS C359,1 AS C360,1 AS C361,1 AS C362,1 AS C363,1 AS C364,1 AS C365,1 AS C366,1 AS C367,1 AS C368,
1 AS C369,1 AS C370,1 AS C371,1 AS C372,1 AS C373,1 AS C374,1 AS C375,1 AS C376,1 AS C377,1 AS C378,1 AS C379,1 AS C380,1 AS C381,1 AS C382,1 AS C383,1 AS C384,
1 AS C385,1 AS C386,1 AS C387,1 AS C388,1 AS C389,1 AS C390,1 AS C391,1 AS C392,1 AS C393,1 AS C394,1 AS C395,1 AS C396,1 AS C397,1 AS C398,1 AS C399,1 AS C400,
1 AS C401,1 AS C402,1 AS C403,1 AS C404,1 AS C405,1 AS C406,1 AS C407,1 AS C408,1 AS C409,1 AS C410,1 AS C411,1 AS C412,1 AS C413,1 AS C414,1 AS C415,1 AS C416,
1 AS C417,1 AS C418,1 AS C419,1 AS C420,1 AS C421,1 AS C422,1 AS C423,1 AS C424,1 AS C425,1 AS C426,1 AS C427,1 AS C428,1 AS C429,1 AS C430,1 AS C431,1 AS C432,
1 AS C433,1 AS C434,1 AS C435,1 AS C436,1 AS C437,1 AS C438,1 AS C439,1 AS C440,1 AS C441,1 AS C442,1 AS C443,1 AS C444,1 AS C445,1 AS C446,1 AS C447,1 AS C448,
1 AS C449,1 AS C450,1 AS C451,1 AS C452,1 AS C453,1 AS C454,1 AS C455,1 AS C456,1 AS C457,1 AS C458,1 AS C459,1 AS C460,1 AS C461,1 AS C462,1 AS C463,1 AS C464,
1 AS C465,1 AS C466,1 AS C467,1 AS C468,1 AS C469,1 AS C470,1 AS C471,1 AS C472,1 AS C473,1 AS C474,1 AS C475,1 AS C476,1 AS C477,1 AS C478,1 AS C479,1 AS C480,
1 AS C481,1 AS C482,1 AS C483,1 AS C484,1 AS C485,1 AS C486,1 AS C487,1 AS C488,1 AS C489,1 AS C490,1 AS C491,1 AS C492,1 AS C493,1 AS C494,1 AS C495,1 AS C496,
1 AS C497,1 AS C498,1 AS C499,1 AS C500,1 AS C501,1 AS C502,1 AS C503,1 AS C504,1 AS C505,1 AS C506,1 AS C507,1 AS C508,1 AS C509,1 AS C510,1 AS C511,1 AS C512,
1 AS D1,1 AS D2,1 AS D3,1 AS D4,1 AS D5,1 AS D6,1 AS D7,1 AS D8,1 AS D9,1 AS D10,1 AS D11,1 AS D12,1 AS D13,1 AS D14,1 AS D15,1 AS D16,
1 AS D17,1 AS D18,1 AS D19,1 AS D20,1 AS D21,1 AS D22,1 AS D23,1 AS D24,1 AS D25,1 AS D26,1 AS D27,1 AS D28,1 AS D29,1 AS D30,1 AS D31,1 AS D32,
1 AS D33,1 AS D34,1 AS D35,1 AS D36,1 AS D37,1 AS D38,1 AS D39,1 AS D40,1 AS D41,1 AS D42,1 AS D43,1 AS D44,1 AS D45,1 AS D46,1 AS D47,1 AS D48,
1 AS D49,1 AS D50,1 AS D51,1 AS D52,1 AS D53,1 AS D54,1 AS D55,1 AS D56,1 AS D57,1 AS D58,1 AS D59,1 AS D60,1 AS D61,1 AS D62,1 AS D63,1 AS D64,
1 AS D65,1 AS D66,1 AS D67,1 AS D68,1 AS D69,1 AS D70,1 AS D71,1 AS D72,1 AS D73,1 AS D74,1 AS D75,1 AS D76,1 AS D77,1 AS D78,1 AS D79,1 AS D80,
1 AS D81,1 AS D82,1 AS D83,1 AS D84,1 AS D85,1 AS D86,1 AS D87,1 AS D88,1 AS D89,1 AS D90,1 AS D91,1 AS D92,1 AS D93,1 AS D94,1 AS D95,1 AS D96,
1 AS D97,1 AS D98,1 AS D99,1 AS D100,1 AS D101,1 AS D102,1 AS D103,1 AS D104,1 AS D105,1 AS D106,1 AS D107,1 AS D108,1 AS D109,1 AS D110,1 AS D111,1 AS D112,
1 AS D113,1 AS D114,1 AS D115,1 AS D116,1 AS D117,1 AS D118,1 AS D119,1 AS D120,1 AS D121,1 AS D122,1 AS D123,1 AS D124,1 AS D125,1 AS D126,1 AS D127,1 AS D128,
1 AS D129,1 AS D130,1 AS D131,1 AS D132,1 AS D133,1 AS D134,1 AS D135,1 AS D136,1 AS D137,1 AS D138,1 AS D139,1 AS D140,1 AS D141,1 AS D142,1 AS D143,1 AS D144,
1 AS D145,1 AS D146,1 AS D147,1 AS D148,1 AS D149,1 AS D150,1 AS D151,1 AS D152,1 AS D153,1 AS D154,1 AS D155,1 AS D156,1 AS D157,1 AS D158,1 AS D159,1 AS D160,
1 AS D161,1 AS D162,1 AS D163,1 AS D164,1 AS D165,1 AS D166,1 AS D167,1 AS D168,1 AS D169,1 AS D170,1 AS D171,1 AS D172,1 AS D173,1 AS D174,1 AS D175,1 AS D176,
1 AS D177,1 AS D178,1 AS D179,1 AS D180,1 AS D181,1 AS D182,1 AS D183,1 AS D184,1 AS D185,1 AS D186,1 AS D187,1 AS D188,1 AS D189,1 AS D190,1 AS D191,1 AS D192,
1 AS D193,1 AS D194,1 AS D195,1 AS D196,1 AS D197,1 AS D198,1 AS D199,1 AS D200,1 AS D201,1 AS D202,1 AS D203,1 AS D204,1 AS D205,1 AS D206,1 AS D207,1 AS D208,
1 AS D209,1 AS D210,1 AS D211,1 AS D212,1 AS D213,1 AS D214,1 AS D215,1 AS D216,1 AS D217,1 AS D218,1 AS D219,1 AS D220,1 AS D221,1 AS D222,1 AS D223,1 AS D224,
1 AS D225,1 AS D226,1 AS D227,1 AS D228,1 AS D229,1 AS D230,1 AS D231,1 AS D232,1 AS D233,1 AS D234,1 AS D235,1 AS D236,1 AS D237,1 AS D238,1 AS D239,1 AS D240,
1 AS D241,1 AS D242,1 AS D243,1 AS D244,1 AS D245,1 AS D246,1 AS D247,1 AS D248,1 AS D249,1 AS D250,1 AS D251,1 AS D252,1 AS D253,1 AS D254,1 AS D255,1 AS D256,
1 AS D257,1 AS D258,1 AS D259,1 AS D260,1 AS D261,1 AS D262,1 AS D263,1 AS D264,1 AS D265,1 AS D266,1 AS D267,1 AS D268,1 AS D269,1 AS D270,1 AS D271,1 AS D272,
1 AS D273,1 AS D274,1 AS D275,1 AS D276,1 AS D277,1 AS D278,1 AS D279,1 AS D280,1 AS D281,1 AS D282,1 AS D283,1 AS D284,1 AS D285,1 AS D286,1 AS D287,1 AS D288,
1 AS D289,1 AS D290,1 AS D291,1 AS D292,1 AS D293,1 AS D294,1 AS D295,1 AS D296,1 AS D297,1 AS D298,1 AS D299,1 AS D300,1 AS D301,1 AS D302,1 AS D303,1 AS D304,
1 AS D305,1 AS D306,1 AS D307,1 AS D308,1 AS D309,1 AS D310,1 AS D311,1 AS D312,1 AS D313,1 AS D314,1 AS D315,1 AS D316,1 AS D317,1 AS D318,1 AS D319,1 AS D320,
1 AS D321,1 AS D322,1 AS D323,1 AS D324,1 AS D325,1 AS D326,1 AS D327,1 AS D328,1 AS D329,1 AS D330,1 AS D331,1 AS D332,1 AS D333,1 AS D334,1 AS D335,1 AS D336,
1 AS D337,1 AS D338,1 AS D339,1 AS D340,1 AS D341,1 AS D342,1 AS D343,1 AS D344,1 AS D345,1 AS D346,1 AS D347,1 AS D348,1 AS D349,1 AS D350,1 AS D351,1 AS D352,
1 AS D353,1 AS D354,1 AS D355,1 AS D356,1 AS D357,1 AS D358,1 AS D359,1 AS D360,1 AS D361,1 AS D362,1 AS D363,1 AS D364,1 AS D365,1 AS D366,1 AS D367,1 AS D368,
1 AS D369,1 AS D370,1 AS D371,1 AS D372,1 AS D373,1 AS D374,1 AS D375,1 AS D376,1 AS D377,1 AS D378,1 AS D379,1 AS D380,1 AS D381,1 AS D382,1 AS D383,1 AS D384,
1 AS D385,1 AS D386,1 AS D387,1 AS D388,1 AS D389,1 AS D390,1 AS D391,1 AS D392,1 AS D393,1 AS D394,1 AS D395,1 AS D396,1 AS D397,1 AS D398,1 AS D399,1 AS D400,
1 AS D401,1 AS D402,1 AS D403,1 AS D404,1 AS D405,1 AS D406,1 AS D407,1 AS D408,1 AS D409,1 AS D410,1 AS D411,1 AS D412,1 AS D413,1 AS D414,1 AS D415,1 AS D416,
1 AS D417,1 AS D418,1 AS D419,1 AS D420,1 AS D421,1 AS D422,1 AS D423,1 AS D424,1 AS D425,1 AS D426,1 AS D427,1 AS D428,1 AS D429,1 AS D430,1 AS D431,1 AS D432,
1 AS D433,1 AS D434,1 AS D435,1 AS D436,1 AS D437,1 AS D438,1 AS D439,1 AS D440,1 AS D441,1 AS D442,1 AS D443,1 AS D444,1 AS D445,1 AS D446,1 AS D447,1 AS D448,
1 AS D449,1 AS D450,1 AS D451,1 AS D452,1 AS D453,1 AS D454,1 AS D455,1 AS D456,1 AS D457,1 AS D458,1 AS D459,1 AS D460,1 AS D461,1 AS D462,1 AS D463,1 AS D464,
1 AS D465,1 AS D466,1 AS D467,1 AS D468,1 AS D469,1 AS D470,1 AS D471,1 AS D472,1 AS D473,1 AS D474,1 AS D475,1 AS D476,1 AS D477,1 AS D478,1 AS D479,1 AS D480,
1 AS D481,1 AS D482,1 AS D483,1 AS D484,1 AS D485,1 AS D486,1 AS D487,1 AS D488,1 AS D489,1 AS D490,1 AS D491,1 AS D492,1 AS D493,1 AS D494,1 AS D495,1 AS D496,
1 AS D497,1 AS D498,1 AS D499,1 AS D500,1 AS D501,1 AS D502,1 AS D503,1 AS D504,1 AS D505,1 AS D506,1 AS D507,1 AS D508,1 AS D509,1 AS D510,1 AS D511,1 AS D512,
1 AS E1,1 AS E2,1 AS E3,1 AS E4,1 AS E5,1 AS E6,1 AS E7,1 AS E8,1 AS E9,1 AS E10,1 AS E11,1 AS E12,1 AS E13,1 AS E14,1 AS E15
) AS Z
UNPIVOT (A FOR O IN (A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,
A17,A18,A19,A20,A21,A22,A23,A24,A25,A26,A27,A28,A29,A30,A31,A32,
A33,A34,A35,A36,A37,A38,A39,A40,A41,A42,A43,A44,A45,A46,A47,A48,
A49,A50,A51,A52,A53,A54,A55,A56,A57,A58,A59,A60,A61,A62,A63,A64,
A65,A66,A67,A68,A69,A70,A71,A72,A73,A74,A75,A76,A77,A78,A79,A80,
A81,A82,A83,A84,A85,A86,A87,A88,A89,A90,A91,A92,A93,A94,A95,A96,
A97,A98,A99,A100,A101,A102,A103,A104,A105,A106,A107,A108,A109,A110,A111,A112,
A113,A114,A115,A116,A117,A118,A119,A120,A121,A122,A123,A124,A125,A126,A127,A128,
A129,A130,A131,A132,A133,A134,A135,A136,A137,A138,A139,A140,A141,A142,A143,A144,
A145,A146,A147,A148,A149,A150,A151,A152,A153,A154,A155,A156,A157,A158,A159,A160,
A161,A162,A163,A164,A165,A166,A167,A168,A169,A170,A171,A172,A173,A174,A175,A176,
A177,A178,A179,A180,A181,A182,A183,A184,A185,A186,A187,A188,A189,A190,A191,A192,
A193,A194,A195,A196,A197,A198,A199,A200,A201,A202,A203,A204,A205,A206,A207,A208,
A209,A210,A211,A212,A213,A214,A215,A216,A217,A218,A219,A220,A221,A222,A223,A224,
A225,A226,A227,A228,A229,A230,A231,A232,A233,A234,A235,A236,A237,A238,A239,A240,
A241,A242,A243,A244,A245,A246,A247,A248,A249,A250,A251,A252,A253,A254,A255,A256,
A257,A258,A259,A260,A261,A262,A263,A264,A265,A266,A267,A268,A269,A270,A271,A272,
A273,A274,A275,A276,A277,A278,A279,A280,A281,A282,A283,A284,A285,A286,A287,A288,
A289,A290,A291,A292,A293,A294,A295,A296,A297,A298,A299,A300,A301,A302,A303,A304,
A305,A306,A307,A308,A309,A310,A311,A312,A313,A314,A315,A316,A317,A318,A319,A320,
A321,A322,A323,A324,A325,A326,A327,A328,A329,A330,A331,A332,A333,A334,A335,A336,
A337,A338,A339,A340,A341,A342,A343,A344,A345,A346,A347,A348,A349,A350,A351,A352,
A353,A354,A355,A356,A357,A358,A359,A360,A361,A362,A363,A364,A365,A366,A367,A368,
A369,A370,A371,A372,A373,A374,A375,A376,A377,A378,A379,A380,A381,A382,A383,A384,
A385,A386,A387,A388,A389,A390,A391,A392,A393,A394,A395,A396,A397,A398,A399,A400,
A401,A402,A403,A404,A405,A406,A407,A408,A409,A410,A411,A412,A413,A414,A415,A416,
A417,A418,A419,A420,A421,A422,A423,A424,A425,A426,A427,A428,A429,A430,A431,A432,
A433,A434,A435,A436,A437,A438,A439,A440,A441,A442,A443,A444,A445,A446,A447,A448,
A449,A450,A451,A452,A453,A454,A455,A456,A457,A458,A459,A460,A461,A462,A463,A464,
A465,A466,A467,A468,A469,A470,A471,A472,A473,A474,A475,A476,A477,A478,A479,A480,
A481,A482,A483,A484,A485,A486,A487,A488,A489,A490,A491,A492,A493,A494,A495,A496,
A497,A498,A499,A500,A501,A502,A503,A504,A505,A506,A507,A508,A509,A510,A511,A512)) AS Z
UNPIVOT (B FOR P IN (B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,
B17,B18,B19,B20,B21,B22,B23,B24,B25,B26,B27,B28,B29,B30,B31,B32,
B33,B34,B35,B36,B37,B38,B39,B40,B41,B42,B43,B44,B45,B46,B47,B48,
B49,B50,B51,B52,B53,B54,B55,B56,B57,B58,B59,B60,B61,B62,B63,B64,
B65,B66,B67,B68,B69,B70,B71,B72,B73,B74,B75,B76,B77,B78,B79,B80,
B81,B82,B83,B84,B85,B86,B87,B88,B89,B90,B91,B92,B93,B94,B95,B96,
B97,B98,B99,B100,B101,B102,B103,B104,B105,B106,B107,B108,B109,B110,B111,B112,
B113,B114,B115,B116,B117,B118,B119,B120,B121,B122,B123,B124,B125,B126,B127,B128,
B129,B130,B131,B132,B133,B134,B135,B136,B137,B138,B139,B140,B141,B142,B143,B144,
B145,B146,B147,B148,B149,B150,B151,B152,B153,B154,B155,B156,B157,B158,B159,B160,
B161,B162,B163,B164,B165,B166,B167,B168,B169,B170,B171,B172,B173,B174,B175,B176,
B177,B178,B179,B180,B181,B182,B183,B184,B185,B186,B187,B188,B189,B190,B191,B192,
B193,B194,B195,B196,B197,B198,B199,B200,B201,B202,B203,B204,B205,B206,B207,B208,
B209,B210,B211,B212,B213,B214,B215,B216,B217,B218,B219,B220,B221,B222,B223,B224,
B225,B226,B227,B228,B229,B230,B231,B232,B233,B234,B235,B236,B237,B238,B239,B240,
B241,B242,B243,B244,B245,B246,B247,B248,B249,B250,B251,B252,B253,B254,B255,B256,
B257,B258,B259,B260,B261,B262,B263,B264,B265,B266,B267,B268,B269,B270,B271,B272,
B273,B274,B275,B276,B277,B278,B279,B280,B281,B282,B283,B284,B285,B286,B287,B288,
B289,B290,B291,B292,B293,B294,B295,B296,B297,B298,B299,B300,B301,B302,B303,B304,
B305,B306,B307,B308,B309,B310,B311,B312,B313,B314,B315,B316,B317,B318,B319,B320,
B321,B322,B323,B324,B325,B326,B327,B328,B329,B330,B331,B332,B333,B334,B335,B336,
B337,B338,B339,B340,B341,B342,B343,B344,B345,B346,B347,B348,B349,B350,B351,B352,
B353,B354,B355,B356,B357,B358,B359,B360,B361,B362,B363,B364,B365,B366,B367,B368,
B369,B370,B371,B372,B373,B374,B375,B376,B377,B378,B379,B380,B381,B382,B383,B384,
B385,B386,B387,B388,B389,B390,B391,B392,B393,B394,B395,B396,B397,B398,B399,B400,
B401,B402,B403,B404,B405,B406,B407,B408,B409,B410,B411,B412,B413,B414,B415,B416,
B417,B418,B419,B420,B421,B422,B423,B424,B425,B426,B427,B428,B429,B430,B431,B432,
B433,B434,B435,B436,B437,B438,B439,B440,B441,B442,B443,B444,B445,B446,B447,B448,
B449,B450,B451,B452,B453,B454,B455,B456,B457,B458,B459,B460,B461,B462,B463,B464,
B465,B466,B467,B468,B469,B470,B471,B472,B473,B474,B475,B476,B477,B478,B479,B480,
B481,B482,B483,B484,B485,B486,B487,B488,B489,B490,B491,B492,B493,B494,B495,B496,
B497,B498,B499,B500,B501,B502,B503,B504,B505,B506,B507,B508,B509,B510,B511,B512)) AS Z
UNPIVOT (C FOR Q IN (C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15,C16,
C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,C31,C32,
C33,C34,C35,C36,C37,C38,C39,C40,C41,C42,C43,C44,C45,C46,C47,C48,
C49,C50,C51,C52,C53,C54,C55,C56,C57,C58,C59,C60,C61,C62,C63,C64,
C65,C66,C67,C68,C69,C70,C71,C72,C73,C74,C75,C76,C77,C78,C79,C80,
C81,C82,C83,C84,C85,C86,C87,C88,C89,C90,C91,C92,C93,C94,C95,C96,
C97,C98,C99,C100,C101,C102,C103,C104,C105,C106,C107,C108,C109,C110,C111,C112,
C113,C114,C115,C116,C117,C118,C119,C120,C121,C122,C123,C124,C125,C126,C127,C128,
C129,C130,C131,C132,C133,C134,C135,C136,C137,C138,C139,C140,C141,C142,C143,C144,
C145,C146,C147,C148,C149,C150,C151,C152,C153,C154,C155,C156,C157,C158,C159,C160,
C161,C162,C163,C164,C165,C166,C167,C168,C169,C170,C171,C172,C173,C174,C175,C176,
C177,C178,C179,C180,C181,C182,C183,C184,C185,C186,C187,C188,C189,C190,C191,C192,
C193,C194,C195,C196,C197,C198,C199,C200,C201,C202,C203,C204,C205,C206,C207,C208,
C209,C210,C211,C212,C213,C214,C215,C216,C217,C218,C219,C220,C221,C222,C223,C224,
C225,C226,C227,C228,C229,C230,C231,C232,C233,C234,C235,C236,C237,C238,C239,C240,
C241,C242,C243,C244,C245,C246,C247,C248,C249,C250,C251,C252,C253,C254,C255,C256,
C257,C258,C259,C260,C261,C262,C263,C264,C265,C266,C267,C268,C269,C270,C271,C272,
C273,C274,C275,C276,C277,C278,C279,C280,C281,C282,C283,C284,C285,C286,C287,C288,
C289,C290,C291,C292,C293,C294,C295,C296,C297,C298,C299,C300,C301,C302,C303,C304,
C305,C306,C307,C308,C309,C310,C311,C312,C313,C314,C315,C316,C317,C318,C319,C320,
C321,C322,C323,C324,C325,C326,C327,C328,C329,C330,C331,C332,C333,C334,C335,C336,
C337,C338,C339,C340,C341,C342,C343,C344,C345,C346,C347,C348,C349,C350,C351,C352,
C353,C354,C355,C356,C357,C358,C359,C360,C361,C362,C363,C364,C365,C366,C367,C368,
C369,C370,C371,C372,C373,C374,C375,C376,C377,C378,C379,C380,C381,C382,C383,C384,
C385,C386,C387,C388,C389,C390,C391,C392,C393,C394,C395,C396,C397,C398,C399,C400,
C401,C402,C403,C404,C405,C406,C407,C408,C409,C410,C411,C412,C413,C414,C415,C416,
C417,C418,C419,C420,C421,C422,C423,C424,C425,C426,C427,C428,C429,C430,C431,C432,
C433,C434,C435,C436,C437,C438,C439,C440,C441,C442,C443,C444,C445,C446,C447,C448,
C449,C450,C451,C452,C453,C454,C455,C456,C457,C458,C459,C460,C461,C462,C463,C464,
C465,C466,C467,C468,C469,C470,C471,C472,C473,C474,C475,C476,C477,C478,C479,C480,
C481,C482,C483,C484,C485,C486,C487,C488,C489,C490,C491,C492,C493,C494,C495,C496,
C497,C498,C499,C500,C501,C502,C503,C504,C505,C506,C507,C508,C509,C510,C511,C512)) AS Z
UNPIVOT (D FOR R IN (D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,D11,D12,D13,D14,D15,D16,
D17,D18,D19,D20,D21,D22,D23,D24,D25,D26,D27,D28,D29,D30,D31,D32,
D33,D34,D35,D36,D37,D38,D39,D40,D41,D42,D43,D44,D45,D46,D47,D48,
D49,D50,D51,D52,D53,D54,D55,D56,D57,D58,D59,D60,D61,D62,D63,D64,
D65,D66,D67,D68,D69,D70,D71,D72,D73,D74,D75,D76,D77,D78,D79,D80,
D81,D82,D83,D84,D85,D86,D87,D88,D89,D90,D91,D92,D93,D94,D95,D96,
D97,D98,D99,D100,D101,D102,D103,D104,D105,D106,D107,D108,D109,D110,D111,D112,
D113,D114,D115,D116,D117,D118,D119,D120,D121,D122,D123,D124,D125,D126,D127,D128,
D129,D130,D131,D132,D133,D134,D135,D136,D137,D138,D139,D140,D141,D142,D143,D144,
D145,D146,D147,D148,D149,D150,D151,D152,D153,D154,D155,D156,D157,D158,D159,D160,
D161,D162,D163,D164,D165,D166,D167,D168,D169,D170,D171,D172,D173,D174,D175,D176,
D177,D178,D179,D180,D181,D182,D183,D184,D185,D186,D187,D188,D189,D190,D191,D192,
D193,D194,D195,D196,D197,D198,D199,D200,D201,D202,D203,D204,D205,D206,D207,D208,
D209,D210,D211,D212,D213,D214,D215,D216,D217,D218,D219,D220,D221,D222,D223,D224,
D225,D226,D227,D228,D229,D230,D231,D232,D233,D234,D235,D236,D237,D238,D239,D240,
D241,D242,D243,D244,D245,D246,D247,D248,D249,D250,D251,D252,D253,D254,D255,D256,
D257,D258,D259,D260,D261,D262,D263,D264,D265,D266,D267,D268,D269,D270,D271,D272,
D273,D274,D275,D276,D277,D278,D279,D280,D281,D282,D283,D284,D285,D286,D287,D288,
D289,D290,D291,D292,D293,D294,D295,D296,D297,D298,D299,D300,D301,D302,D303,D304,
D305,D306,D307,D308,D309,D310,D311,D312,D313,D314,D315,D316,D317,D318,D319,D320,
D321,D322,D323,D324,D325,D326,D327,D328,D329,D330,D331,D332,D333,D334,D335,D336,
D337,D338,D339,D340,D341,D342,D343,D344,D345,D346,D347,D348,D349,D350,D351,D352,
D353,D354,D355,D356,D357,D358,D359,D360,D361,D362,D363,D364,D365,D366,D367,D368,
D369,D370,D371,D372,D373,D374,D375,D376,D377,D378,D379,D380,D381,D382,D383,D384,
D385,D386,D387,D388,D389,D390,D391,D392,D393,D394,D395,D396,D397,D398,D399,D400,
D401,D402,D403,D404,D405,D406,D407,D408,D409,D410,D411,D412,D413,D414,D415,D416,
D417,D418,D419,D420,D421,D422,D423,D424,D425,D426,D427,D428,D429,D430,D431,D432,
D433,D434,D435,D436,D437,D438,D439,D440,D441,D442,D443,D444,D445,D446,D447,D448,
D449,D450,D451,D452,D453,D454,D455,D456,D457,D458,D459,D460,D461,D462,D463,D464,
D465,D466,D467,D468,D469,D470,D471,D472,D473,D474,D475,D476,D477,D478,D479,D480,
D481,D482,D483,D484,D485,D486,D487,D488,D489,D490,D491,D492,D493,D494,D495,D496,
D497,D498,D499,D500,D501,D502,D503,D504,D505,D506,D507,D508,D509,D510,D511,D512)) AS Z
UNPIVOT (E FOR S IN (E1,E2,E3,E4,E5,E6,E7,E8,E9,E10,E11,E12,E13,E14,E15)) AS Z
) --1,030,792,151,040 rows
SELECT COUNT_BIG(ALL CASE
WHEN row%15 = 0 THEN 'FIZZBUZZ'
WHEN row%5 = 0 THEN 'BUZZ'
WHEN row%3 = 0 THEN 'FIZZ'
ELSE CAST(row AS VARCHAR(14))
END)
FROM cte1 WHERE row < 1000000000001 --set limit to 1 trillion
March 15, 2010 at 4:26 am
steve-893342 (3/15/2010)
Wow Mister Magoo, that ROW CONSTRUCTOR syntax is certainly a lot more friendly than UNPIVOT. Seeing your script, I just had to create the UNPIVOT equivalent which is a bit of a monster! I have tested this at the 4 billion limit and it performs very poorly. It looks as if maybe tall and thin is good for multiple UNPIVOTS whereas short and fat is good for the ROW CONSTRUCTOR. Who would have thought that eh? BTW I hope you appreciate this one. It took me ages to type it out!
I really really hope you are joking about typing all that in!
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
March 15, 2010 at 6:41 am
What do you think?:laugh:
March 15, 2010 at 6:49 am
steve-893342 (3/15/2010)
What do you think?:laugh:
I think you did like me and used the solution to generate other solutions?
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
March 17, 2010 at 5:50 pm
THE TRILLION - CROSS APPLY Version
The CROSS APPLY variation (cf Post #882552) of THE TRILLION has edged out both multiple unpivots and the CTE version of the table join. This refinement starts with a CTE holding just 2 rows and then with 5 successive CROSS APPLY CTEs releases over 1 trillion rows.
Timed at
61 hours 43 minutes
Data from sys.dm_exec_query_stats
total_elapsed_time 222,160,341,797
total_worker_time 221,973,559,632
total_physical_reads 0
total_logical_reads 0
And yes there probably is an analagous CROSS JOIN variation of this query. It just evolved into the CROSS APPLY form. I believe the trick of this query is the number sequence (2, 6, 36, 1296, 1679616, 1099511905536) in being an efficient way of releasing over 1 trillion rows with only 2 UNION ALL statements in the entire query. If you reduce the number of CTEs and at the same increase the number of UNION ALL statements, my data suggest it becomes more inefficient.
March 17, 2010 at 6:37 pm
http://www.sqlservercentral.com/Forums/FindPost882751.aspx
THE TRILLION - VALUES of 512 rows
Well, this one turned out not to scale well and came in at 66 hours...
I am now officially done with this :crazy:
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
Viewing 15 posts - 271 through 285 (of 363 total)
You must be logged in to reply to this topic. Login to reply