Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Transposing two rows of data to one row Expand / Collapse
How I can do this in SQL
Poll ResultsVotes
I have tried a few times and I am not getting it right.
0%
0
I appreciate if you can help.
0%
0
Regards
0%
0
Member Votes: 0, Anonymous Votes: 0. You don't have permission to vote within this poll.
Author
Message
Posted Thursday, July 4, 2013 4:17 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 20, 2013 3:24 AM
Points: 2, Visits: 22
I have a large table of 2m records and I need to combine every two Document No_ to one row and placing the other fields on one row against it as below:

Document No_ Dimension Code Dimension Value Code
------------------------------------------------------------------------------------------
SHP99994 DEPARTMENT MHT
SHP99994 TRADETYPE M


I would like the code change the above display to the following:

Document No_ Dimension Value Code_1 Dimension Value Code_2
-----------------------------------------------------------------------------------------------
SHP99994 MHT M

Can you help please?
Thank you in advance
Post #1470388
Posted Thursday, July 4, 2013 4:36 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 2:11 PM
Points: 1,681, Visits: 19,596

SELECT DocumentNo_,
MAX(CASE WHEN DimensionCode='DEPARTMENT' THEN DimensionValueCode END) AS DimensionValueCode_1,
MAX(CASE WHEN DimensionCode='TRADETYPE' THEN DimensionValueCode END) AS DimensionValueCode_2
FROM myTable
GROUP BY DocumentNo_



____________________________________________________

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1470392
Posted Friday, July 5, 2013 4:32 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 20, 2013 3:24 AM
Points: 2, Visits: 22
Thank you very much for your help.
I have tested the code and It worked .

Thank you,
Alan
Post #1470653
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse