September 10, 2013 at 3:11 pm
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.
September 10, 2013 at 4:13 pm
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
September 11, 2013 at 6:23 am
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.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply