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

how to get data from a table all in one result row Expand / Collapse
Author
Message
Posted Tuesday, September 10, 2013 3:11 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, December 30, 2013 6:50 AM
Points: 196, Visits: 402
I'm need help with a query.
The table has an id, a name, and a type. Sample:
ID Name Type
123 description black
123 technique breaking
456 findings nice
456 technique splitting

How can I select to get this result:
123 black breaking
456 nice splitting

Thanks very much for any help.
Post #1493370
Posted Tuesday, September 10, 2013 4:13 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 3:44 PM
Points: 2,763, Visits: 5,901
You can use cross tabs to accomplish this. To read more about this technique, read the following article.
http://www.sqlservercentral.com/articles/T-SQL/63681/
SELECT ID,
MAX( CASE WHEN Name = 'Description' THEN Type) AS Description,
MAX( CASE WHEN Name = 'technique ' THEN Type) AS Technique
FROM MyTable
GROUP BY ID




Luis C.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1493387
Posted Wednesday, September 11, 2013 6:23 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, December 30, 2013 6:50 AM
Points: 196, Visits: 402
This worked, I had to add an else and end and it worked like I needed.
SELECT ID,
MAX( CASE WHEN Name = 'Description' THEN Type else null end) AS Description,
MAX( CASE WHEN Name = 'technique ' THEN Type else null end) AS Technique
FROM MyTable
GROUP BY ID

Thanks very much.


Post #1493614
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse