473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Transposing Data of Table as Columns in SQL

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.
Oct 18 '07 #1
1 1464
dusana
3
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'
Oct 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Fabio | last post by:
Hello, is there any quite easy solution for the problem of transposing the rows into the columns? I have the following table with some data in it: dealer date 09.00 10.00 11.00 ...
8
by: Leszek Gruszka | last post by:
Hello! I need to transpose some columns into rows and rows into columns. I know, tha i can do it by cursor, but i don't know how make it... I read a lot about it, but still don't understand......
0
by: Christoph Lutz | last post by:
Hi, I would like to transpose a table in mysql. I have looked on the web for a while but nothing seems to fit the bill, so I just want to clarify if I have to write some php or if I can use a...
2
by: Howard William | last post by:
Help. I am a bit flummoxed by the problem of how to transpose "normalized" (in the database sense) data records into columns of for a data entry form, and then back again when the user is...
9
by: Classic-Car-World Ltd | last post by:
Hi, I have some data in a table in columns which I need to convert into rows. This is specification data for some tools etc. The data is currently in the following format: Product No, order,...
4
by: m.wanstall | last post by:
Hi there, I have a large table based around a CustomerNumber with various details about that customer (originally imported and augmented from an Exchange Server)...now, a single customer can...
1
by: trizub | last post by:
I have a table of populations of cities (identified by country, state, cities) on particular dates. How do I transpose the date values in my rows to a date value column that lists populations for...
3
by: newb | last post by:
Hey guys, I’m new to access and databases and I’m having a bit of trouble coming up with a query that will do what I need. I have three tables in the form of: Table 1: Category ID, Category ...
11
by: Haydee Zimmerman | last post by:
Hoping someone can help me. I have 2 Access tables with a one to many relationship. the 1 side table holds the billing information, the many table side holds the billing id and modifier#. Now I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.