Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Convert column values to column
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

147 Posts

Posted - 01/22/2014 :  06:14:14  Show Profile  Reply with Quote
Dear All,

I have a query, where i have a table where two columns is there.

I want to convert first column records in Column header and second column records would come under that header.

Col1	Col2		
FirstName     	Ajay		
LastName	Nath		
DOB	25/08/1981		
Gender	Male		
FirstName     	LastName	DOB	Gender
Ajay	Nath	25/08/1981	Male

Please help me

Aged Yak Warrior

545 Posts

Posted - 01/22/2014 :  06:42:03  Show Profile  Reply with Quote

with aCTE
AS (
		select 'FirstName' as Col1, 'Ajay' as Col2 union all
		select 'LastName',	'Nath' union all
		select 'DOB',	'25/08/1981' union all
		select 'Gender'	,'Male'

		max(col2) FOR col1 in ([FirstName],[LastName],[DOB],[Gender])) AS x;				

Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000