Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Alternate rows into colums

Author  Topic 

udayfn12
Starting Member

15 Posts

Posted - 2004-03-18 : 16:16:20
Hi,

I need help on this simple query. I need to get the alternate rows into horizontal columns. I have provided the data and output format.

Any help would be appreciated.

Thanks in advance,
Reddy.

Output Format:
-------------
DESCRIPTION  LINE  VALUE  LINE VALU
TESTINGA100   A100   8768   A110    23
TESTING120   A120   2314   A130   87
TESTING140   A140   4568   A150   3

Create Table:
create table testLINE
(Linitem varchar(5), description varchar(20), value float)
Data:
insert into testLINE
values ('A100','TESTINGA100',8768)
insert into testLINE
values ('A110','TESTINGA1',23)
insert into testLINE
values ('A120','TESTINGA120',2314)
insert into testLINE
values ('A130','TESTINGA13',87)
insert into testLINE
values ('A140','TESTING140',4568)
insert into testLINE
values ('A150','TESTING115',3)

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-03-18 : 18:46:17
[code]
select
identity(int,0,1) id, linitem,description,value
into #testline
from testline

select *
from #testline t1
join #testline t2 on t2.id-1 = t1.id
where t1.id%2 = 0 and t2.id%2 = 1

drop table #testline[/code]
Go to Top of Page

udayfn12
Starting Member

15 Posts

Posted - 2004-03-20 : 14:57:15
Thanks a lot. It helped me.

Reddy.

Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-03-20 : 14:58:38
Glad that helped you Reddy.
Go to Top of Page
   

- Advertisement -