Link to home
Start Free TrialLog in
Avatar of gwarcher
gwarcher

asked on

SQL Server or Excel - transpose columns to rows

I have a table that looks like this:

District   Code    SubDistrict1   SubDistrict2   Subdistrict3
A             11         Apple                Orange            Pear
B             131      Banana               Wood              Desert
C             53         Apple               Salt                  Pepper


And I need it to look like this:

District   Code    Subdistrict
A              11        Apple
A              11       Orange
etc...
C            53        Apple
etc...

Normally this would be simple but I have thousands of rows with several hundred different codes. Is there a simple automated way to lay this out in SQL?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gwarcher
gwarcher

ASKER

Both worked perfectly. Thank you.