Rearrange Rows and Columns - TechRepublic
Question
April 14, 2008 at 09:52 AM
joshgamble

Rearrange Rows and Columns

by joshgamble . Updated 18 years, 2 months ago

I have a table with three columns:
AcctNbr, Type, CodeValue

Listed below is an example of the database.

AcctNbr Type CodeValue
1 MAILCODE 99
2 MAILCODE 99
3 MAILCODE 99
4 MAILCODE 90
4 MAILCODE 99
4 SEG1 O
5 MAILCODE 99
6 MAILCODE 99
7 MAILCODE 99
8 MAILCODE 99
9 MAILCODE 99
10 MAILCODE 90
11 MAILCODE 99
12 MAILCODE 99
13 MAILCODE 99
14 MAILCODE 99
15 LIST DS1
15 MAILCODE 99

There are multiple Type’s for some AcctNbr’s and what I want to do is
run a query on the database so that if the AcctNbr has multiple Type’s
and CodesValue’s it takes them and creates new columns like so:

AcctNbr MailCode_90 MailCode_99 SEG1
4 90 99 O

So on and so forth. There are multiple Type’s and multiple codes that
I need to do this with for each account number. If someone could give
me a base code to try I could start somewhere. I am an SQL novice.
Thanks.

Josh

This discussion is locked

All Comments