|
|
|
Click here to copy the following block | CREATE TABLE #e ( Line1 int, Line2 int, Line3 int, Line4 int, Line5 int ) INSERT INTO #e VALUES ( 1, 2, 3, 4, 5 ); INSERT INTO #e VALUES ( 11, 22, 33, 44, 55 ); SELECT * FROM #e;
GO
SELECT number AS line , CASE number WHEN 1 THEN line1 WHEN 2 THEN line2 WHEN 3 THEN line3 WHEN 4 THEN line4 WHEN 5 THEN line5 END AS value FROM #e JOIN (
SELECT number FROM Numbers WHERE number Between 1 And 5 ) AS n ON 1 = 1 ORDER BY line, value;
SELECT 1 AS line, line1 AS value FROM #e UNION ALL SELECT 2, line2 FROM #e UNION ALL SELECT 3, line3 FROM #e UNION ALL SELECT 4, line4 FROM #e UNION ALL SELECT 5, line5 FROM #e;
SELECT CASE WHEN (GROUPING(line1) = 0 and GROUPING(line2) = 1 and GROUPING(line3) = 1 and GROUPING(line4) = 1 and GROUPING(line5) = 1) THEN 1 WHEN (GROUPING(line1) = 1 and GROUPING(line2) = 0 and GROUPING(line3) = 1 and GROUPING(line4) = 1 and GROUPING(line5) = 1) THEN 2 WHEN (GROUPING(line1) = 1 and GROUPING(line2) = 1 and GROUPING(line3) = 0 and GROUPING(line4) = 1 and GROUPING(line5) = 1) THEN 3 WHEN (GROUPING(line1) = 1 and GROUPING(line2) = 1 and GROUPING(line3) = 1 and GROUPING(line4) = 0 and GROUPING(line5) = 1) THEN 4 WHEN (GROUPING(line1) = 1 and GROUPING(line2) = 1 and GROUPING(line3) = 1 and GROUPING(line4) = 1 and GROUPING(line5) = 0) THEN 5 END AS Line, COALESCE( line1, line2, line3, line4, line5 ) AS value FROM #e GROUP BY line1, line2, line3, line4, line5 WITH CUBE HAVING (GROUPING(line1) = 0 and GROUPING(line2) = 1 and GROUPING(line3) = 1 and GROUPING(line4) = 1 and GROUPING(line5) = 1) or (GROUPING(line1) = 1 and GROUPING(line2) = 0 and GROUPING(line3) = 1 and GROUPING(line4) = 1 and GROUPING(line5) = 1) or (GROUPING(line1) = 1 and GROUPING(line2) = 1 and GROUPING(line3) = 0 and GROUPING(line4) = 1 and GROUPING(line5) = 1) or (GROUPING(line1) = 1 and GROUPING(line2) = 1 and GROUPING(line3) = 1 and GROUPING(line4) = 0 and GROUPING(line5) = 1) or (GROUPING(line1) = 1 and GROUPING(line2) = 1 and GROUPING(line3) = 1 and GROUPING(line4) = 1 and GROUPING(line5) = 0); GO |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|