Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...The enviroment is simple, natural and efficient. The members are competent, educated and professionals..."

Geography

Where in the world do Tek-Tips members come from?
mayamanako (TechnicalUser)
6 May 12 11:53
Hi guys, can you give me some ideas as to how I'd tackle this problem please?

My table has 3 columns, all text:
col1  col2  col3

How do I make it into a recordset that looks something like this?
col1
col2
col3

Thanks for any suggestions?
draigGoch (Programmer)
6 May 12 14:40
You need to use a Cross-tab/Pivot query.
For example, you have a table called tblSales:

Year     |     Sales
--------------
2011    |     10000
2010    |     9000
2009    |     8000

SELECT [2009],[2010],[2011]
FROM tblSales
PIVOT
(
  MAX(Sales)
  FOR [Year] IN ([2011],[2010],[2009]);
)
AS mySales

Will Output:

2009     |     2010     |     2011
-------------------------
10000   |     9000     |     8000

A computer always does what you tell it to, but rarely does what you want it to.....

Helpful Member!  r937 (TechnicalUser)
6 May 12 17:11

draigGoch, i think what the original poster is after is "unpivot"

Quote:

My table has 3 columns, all text:
col1  col2  col3

How do I make it into a recordset that looks something like this?
col1
col2
col3

CODE

SELECT col1 FROM daTable
UNION ALL
SELECT col2 FROM daTable
UNION ALL
SELECT col3 FROM daTable


 

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

mayamanako (TechnicalUser)
6 May 12 18:37
Wow, thanks very much r937, it worked like magic!
draigGoch (Programmer)
8 May 12 6:33
Ah yes - That should teach me to read it properly!

A computer always does what you tell it to, but rarely does what you want it to.....

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close