Connecting Tech Pros Worldwide Forums | Help | Site Map

Transposing Data of Table as Columns in SQL

Newbie
 
Join Date: Nov 2006
Location: California
Posts: 24
#1: Oct 18 '07
Lets consider the following query:

Expand|Select|Wrap|Line Numbers
  1. Select Col1, Col2 from Table1 where Colx = 'A5100650867'
This gives result as:
Expand|Select|Wrap|Line Numbers
  1. Col1                         Col2
  2. E-mail Address                xyz@GMAIL.com
  3. Web Site                      www.GOOGLE.com
I want the outcome as:

Expand|Select|Wrap|Line Numbers
  1. E-mail Address         Web Site
  2. xyz@GMAIL.com           www.GOOGLE.com
So the new columns inthe resultset are 'E-mail Address' and 'Web Site'.

[HTML]Note: This is just a simple example I have considered. Potentially there can be multiple things like that e.g. E-Mail, E-Mail2, Pager, Mobile etc etc...[/HTML]

Please advice on this. Thank you.

Newbie
 
Join Date: Oct 2007
Posts: 3
#2: Oct 22 '07

re: Transposing Data of Table as Columns in SQL


Quote:

Originally Posted by TimHop12

Lets consider the following query:

Expand|Select|Wrap|Line Numbers
  1. Select Col1, Col2 from Table1 where Colx = 'A5100650867'
This gives result as:
Expand|Select|Wrap|Line Numbers
  1. Col1                         Col2
  2. E-mail Address                xyz@GMAIL.com
  3. Web Site                      www.GOOGLE.com
I want the outcome as:

Expand|Select|Wrap|Line Numbers
  1. E-mail Address         Web Site
  2. xyz@GMAIL.com           www.GOOGLE.com
So the new columns inthe resultset are 'E-mail Address' and 'Web Site'.

[HTML]Note: This is just a simple example I have considered. Potentially there can be multiple things like that e.g. E-Mail, E-Mail2, Pager, Mobile etc etc...[/HTML]

Please advice on this. Thank you.



try this

Select ltrim(rtrim(Col1)) as Col1, ltrim(rtrim(Col2)) as Col2 from Table1 where Colx = 'A5100650867'
Reply


Similar Microsoft SQL Server bytes