Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a "pivot table" using SQL - ASAP

Status
Not open for further replies.

1cutedimple

Programmer
Feb 27, 2004
11
0
0
CA
I have a table which looks like this:

Account# | Debit_Points | Bonus_points | Offer
123456789| 22 | 5 | MULTI10
234567890| 0 | 50 | MULTI20
987654100| 109 | 100 | MULTI30

I need to create a table that looks like this:

Account# | Debit_Points | MULTI10 | MULTI20 | MULTI30
123456789| 22 | 5 | |
234567890| 0 | | 50 |
987654100| 109 | | | 100

How can I do this using SQL?
Thanks in advance!
 
Try something like:

[tt]
SELECT AccountNum, Debit_Points,
CASE WHEN Multi10 THEN Multi10 ELSE 0 END AS Multi10,
CASE WHEN Multi20 THEN Multi20 ELSE 0 END AS Multi20,
CASE WHEN Multi30 THEN Multi30 ELSE 0 END AS Multi30

FROM ...
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top