January 28, 2011 at 3:49 am
Folks,
I have three subqueries i made them as single and returned three columns as a|b|c
now i need to changes this into single rows
as
a
b
c
need urgent help
January 28, 2011 at 6:22 am
do you have any examples of what you are doing? It's easier if you provide code, sample data and expected results instead of some ambiguous urgent request
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
January 31, 2011 at 2:40 am
February 1, 2011 at 7:17 am
sound like UNPIVOT to me, although you have a very sparse description of what you actually need and no sample data/code/expected outcome.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
February 1, 2011 at 7:22 am
lefrancisco1 (1/28/2011)
Folks,I have three subqueries i made them as single and returned three columns as a|b|c
now i need to changes this into single rows
as
a
b
c
need urgent help
Does each subquery return one of each of the columns? If so, just don't do that. Have them all return to the same column using UNION ALL.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 1, 2011 at 7:46 am
lefrancisco1 (1/28/2011)
Folks,I have three subqueries i made them as single and returned three columns as a|b|c
now i need to changes this into single rows
as
a
b
c
need urgent help
Simple pivot example: -
DECLARE @table AS TABLE(Id INT, Product CHAR(5), TT INT, Week CHAR(2))
INSERT INTO @table
SELECT 1, 'Test1', 75, '1'
UNION ALL SELECT 2, 'Test2', 20, '1'
UNION ALL SELECT 3, 'Test1', 60, '2'
UNION ALL SELECT 4, 'Test2', 40, '2'
UNION ALL SELECT 5, 'Test1', 35, '3'
UNION ALL SELECT 6, 'Test2', 65, '3'
SELECT pivoteddata.*
FROM (SELECT product, tt, week
FROM @table) AS rawdata
PIVOT (MAX(tt) FOR week IN ([1], [2], [3])) AS pivoteddata
Also, read Jeff's wonderful articles -Part 1[/url], Part 2[/url]
February 1, 2011 at 7:56 am
skcadavre (2/1/2011)
lefrancisco1 (1/28/2011)
Folks,I have three subqueries i made them as single and returned three columns as a|b|c
now i need to changes this into single rows
as
a
b
c
need urgent help
Simple pivot example: -
DECLARE @table AS TABLE(Id INT, Product CHAR(5), TT INT, Week CHAR(2))
INSERT INTO @table
SELECT 1, 'Test1', 75, '1'
UNION ALL SELECT 2, 'Test2', 20, '1'
UNION ALL SELECT 3, 'Test1', 60, '2'
UNION ALL SELECT 4, 'Test2', 40, '2'
UNION ALL SELECT 5, 'Test1', 35, '3'
UNION ALL SELECT 6, 'Test2', 65, '3'
SELECT pivoteddata.*
FROM (SELECT product, tt, week
FROM @table) AS rawdata
PIVOT (MAX(tt) FOR week IN ([1], [2], [3])) AS pivoteddata
Also, read Jeff's wonderful articles -Part 1[/url], Part 2[/url]
I really appreciate the glowing review but the op wants to UNpivot.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 1, 2011 at 8:10 am
What about:
SELECT 'a'
UNION
SELECT 'b'
UNION
SELECT 'c'
Regards,
Iulian
February 1, 2011 at 8:36 am
Jeff Moden (2/1/2011)
I really appreciate the glowing review but the op wants to UNpivot.
And that's what comes from skimming the first post and not reading the thread. . .
February 1, 2011 at 8:47 am
What am I - chopped liver? I think I did mention UNpivot, right?? :hehe:
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
February 1, 2011 at 9:18 am
TheSQLGuru (2/1/2011)
What am I - chopped liver? I think I did mention UNpivot, right?? :hehe:
Yep yep, my bad. Skimmed the first post. Only came on here because I was thinking about how to re-write an awful stored procedure that I've inherited. I'm going to go and sit in the naughty corner for awhile, k? :blush:
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply