MS SQL Merge 2 rows to 2 columns.

I have a table with data like this:


idx                    Serial_No             Model     Line      Lower          Upper      Spec.      Data
34697      9KV4A11000003      T021-0      B      0.03                  0.076        54              0.02
34698      9KV4A11000003      T021-0      B      0.03                  0.076        54              0.01
43653      9KV4A11000034      TOK1-0      B      0.03             0.076        60              0.03
43654      9KV4A11000034      TOK1-0      B      0.03                  0.076        60              0.03
...............................................
Each Serial_No has 2 records (2 rows).
I want to select to data like this:
idx                    Serial_No             Model     Line      Lower          Upper      Spec.      Data    Data2
34697      9KV4A11000003      T021-0      B      0.03                  0.076        54              0.02     0.01
43653      9KV4A11000034      TOK1-0      B      0.03             0.076        60              0.03     0.03
........................................
(Moves the second row to new column Data2)

Please help me.
JameMeckAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LowfatspreadCommented:
;with cte as (select x.*
                        ,row_number() over (partition by idx,serial_number,model,line,lower,upper,[spec.]
                             order by [data] desc) as rn
                     from yopurtable as x
                   )
select a.*
         ,[1] as [Data],[2] as [Data2]
  from cte as a
 pivot (max(data) for rn in ([1],[2])) as pvt
order by idx,serial_no,model,line,lower,upper,[spec.]
LowfatspreadCommented:
sorry


;with cte as (select x.*
                        ,row_number() over (partition by idx,serial_number,model,line,lower,upper,[spec.]
                             order by [data] desc) as rn
                     from yopurtable as x
                   )
select  idx,serial_no,model,line,lower,upper,[spec.]
         ,[1] as [Data],[2] as [Data2]
  from cte as a
 pivot (max(data) for rn in ([1],[2])) as pvt
order by idx,serial_no,model,line,lower,upper,[spec.]

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JameMeckAuthor Commented:
Thanks! I got it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.