pivoting in sql server columns to rows

we have this sql (sql server)

select c.SAMPLE_NUMBER, f.AMOUNT
from daily_arg c
left outer join daily_results f on c.arg_GUID = f.arg_GUID
and f.RANK = 0
where c.PROJECT_NUMBER = '99-9999'
and c.SAMPLE_NUMBER is not null
order by c.SAMPLE_NUMBER

and the out put is like this

1    $11    
2    $435.57    
3    $233    
4    $12
5    $55    
6    $69        
7    $4.68  
8    $65
9    $45    
10   $1.08      
11   $21    
12   $4.50

=====
and we want the output to look like this

1    $11    2    $435.57    3     $233     4    $12
5    $55    6    $69           7     $4.68    8    $65
9    $45    10   $1.08       11    $21      12   $4.50


4 entries  for each row how can we achieve this



LVL 11
it-rexAsked:
Who is Participating?
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.

xizwyckCommented:
This has what you need. Just adapt the SQL for your needs:

http://msdn.microsoft.com/en-us/library/ms177410.aspx


it-rexAuthor Commented:
I have seen all these ,
but still could not do it.
EmesCommented:
This may get you closer

select c.SAMPLE_NUMBER, sum(f.AMOUNT)
from daily_arg c
left outer join daily_results f on c.arg_GUID = f.arg_GUID
and f.RANK = 0
where c.PROJECT_NUMBER = '99-9999'
and c.SAMPLE_NUMBER is not null
order by c.SAMPLE_NUMBER
group by
 c.SAMPLE_NUMBER/4,c.SAMPLE_NUMBER % 4
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

cyberkiwiCommented:
This will do it

;with tmp as (
      select c.SAMPLE_NUMBER, f.AMOUNT, rn=row_number() over (order by c.SAMPLE_NUMBER)
      from daily_arg c
      left outer join daily_results f on c.arg_GUID = f.arg_GUID
      and f.RANK = 0
      where c.PROJECT_NUMBER = '99-9999'
      and c.SAMPLE_NUMBER is not null
)
select a.sample, a.amount, b.sample, b.amount, c.sample, c.amount, d.sample, d.amount
from tmp a
left join tmp b on b.rn=a.rn+1
left join tmp c on c.rn=a.rn+2
left join tmp d on d.rn=a.rn+3
where a.rn % 4 = 1
order by a.rn

but... why!  This should be done from the front end...
Your call
cyberkiwiCommented:
Correction to field name

;with tmp as (
      select c.SAMPLE_NUMBER, f.AMOUNT, rn=row_number() over (order by c.SAMPLE_NUMBER)
      from daily_arg c
      left outer join daily_results f on c.arg_GUID = f.arg_GUID
      and f.RANK = 0
      where c.PROJECT_NUMBER = '99-9999'
      and c.SAMPLE_NUMBER is not null
)
select a.SAMPLE_NUMBER, a.amount, b.SAMPLE_NUMBER, b.amount, c.SAMPLE_NUMBER, c.amount, d.SAMPLE_NUMBER, d.amount
from tmp a
left join tmp b on b.rn=a.rn+1
left join tmp c on c.rn=a.rn+2
left join tmp d on d.rn=a.rn+3
where a.rn % 4 = 1
order by a.rn

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
it-rexAuthor Commented:
Amazing;
thanks alot
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

From novice to tech pro — start learning today.