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.
| 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 VALUTESTINGA100 A100 8768 A110 23TESTING120 A120 2314 A130 87TESTING140 A140 4568 A150 3Create Table:create table testLINE(Linitem varchar(5), description varchar(20), value float)Data:insert into testLINEvalues ('A100','TESTINGA100',8768)insert into testLINEvalues ('A110','TESTINGA1',23)insert into testLINEvalues ('A120','TESTINGA120',2314)insert into testLINEvalues ('A130','TESTINGA13',87)insert into testLINEvalues ('A140','TESTING140',4568)insert into testLINEvalues ('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,valueinto #testlinefrom testlineselect *from #testline t1join #testline t2 on t2.id-1 = t1.idwhere t1.id%2 = 0 and t2.id%2 = 1 drop table #testline[/code] |
 |
|
|
udayfn12
Starting Member
15 Posts |
Posted - 2004-03-20 : 14:57:15
|
| Thanks a lot. It helped me.Reddy. |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2004-03-20 : 14:58:38
|
| Glad that helped you Reddy. |
 |
|
|
|
|
|
|
|