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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transpose Fields

Status
Not open for further replies.

AGGGG

Programmer
Oct 8, 2003
20
GB
Hi,

I am trying to transpose data in a table, so that it can be imported into another software package. Hence, I cannot change the format.

Hopefuly the data below will help explain my request. Any help would be appreciated.

Cheers, Andy

Current Data:
From To 0-10 11-20
AMS GLA 1 2
EDI LHR 3 4

Reuired Format:
From To
AMS GLA 0-10 1
AMS GLA 11-20 2
EDI LHR 0-10 3
EDI LHR 11-20 4
 
Something like:

Code:
select fromtext, totext, [0-10]
from yourtable
where [0-10] mod 2 = 1
union
select fromtext, totext, [11-20]
from yourtable
where [11-20] mod 2 = 0
order by fromtext, totext, 3

John
 
Code:
SELECT [From]
     , [To]
     , '0-10' AS []
     , [0-10] AS []
  FROM daTable
UNION ALL
SELECT [From]
     , [To]
     , '11-20' 
     , [11-20]

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top