Click here to Skip to main content
15,887,917 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have 2 table with the following details.

UserTable
Id          Name          Place
----------- ------------------------                                          
1           Vidya          Delhi
2           Minu           Banglore

Detail Table
ID      SPEC     Qualification
-------------------------------------
1       Hi       +2
1       Hello    Degree


Actually i want the out put in below format

UserID Name    Place   Spec  Qualification  ED1     ED2
----------- -----------------------------------------------------------

1      Vidya   Delhi   Hi     +2            Hello   Degree


Please update with the query
Thanx in advance
Saju A
Posted
Updated 29-Nov-12 9:14am
v2

Read my article about dynamic pivotting[^].
 
Share this answer
 
I've found not exact solution, but i hope it would be helpful.
SQL
SELECT  [ID] AS [UserID], [Name], [Place],
		STUFF( (SELECT', ' + [Spec] AS 'text()'
                  FROM @detailtable t2
                  WHERE t2.[ID] = t1.[ID]
                  FOR XML PATH('')), 1, 1, '') AS [Specs],
		STUFF( (SELECT', ' + [Qualification] AS 'text()'
                  FROM @detailtable t2
                  WHERE t2.[ID] = t1.[ID]
                  FOR XML PATH('')), 1, 1, '') AS [Qualifications]
   FROM @usertable t1
GROUP BY [ID], [Name], [Place]
GO


Result:

UserIDNamePlaceSpecsQualifications
1VidyaDelphiHi, Hello+2, Degree
2MinuBangloreNULLNULL
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900