j_jst


Hi genius,

I got the result set as shown below (By executing another query i got this).

Month   Status   Count
===== ======  =====
April   I   129
April   O   4689
April   S   6
July   I   131
July   O   4838
July   S   8
June   I   131
June   O   4837
June   S   8
May   I   131
May   O   4761
May   S    7

But, I need the same result set as below


Month   I        O       S
=====  =       =       =
April    129    4689    6
July     131    4838    8
June    131    4837    8
May     131    4761    7 
 

Can anyone provide me the tips/solution.

Thanks in advance

Regards,
j_jst




Re: Convert Rows into Columns... (Cross tab).

Nan Tu


You can try "Pivot transformation". Book online has examples.




Re: Convert Rows into Columns... (Cross tab).

Harris Sayed

You can also select the cells, copy, shift F10, select paste and transpose. The selected rows will copy in columnar form.

Good Luck







Re: Convert Rows into Columns... (Cross tab).

Joshker

Hi,

I also have a same problem. Can you suggest what was your solution

regards

Josh





Re: Convert Rows into Columns... (Cross tab).

Jon Royales

I also need to do something similar...

It was suggested that I would probably need to use a cursor in a stored procedure which loops through the rows and updates a temporary table with the values I need.

I havenĄŻt got round to doing this yetĄ­ so if anybody has a solution which I could have a look at IĄŻd be very grateful.

IĄŻll post my solution when IĄŻve got it.





Re: Convert Rows into Columns... (Cross tab).


Re: Convert Rows into Columns... (Cross tab).

Mark - SQL

select [Month],
max(case when [Status]='I' then [Count] end) as I,
max(case when [Status]='O' then [Count] end) as O,
max(case when [Status]='S' then [Count] end) as S
from mytable
group by [Month]
order by [Month]





Re: Convert Rows into Columns... (Cross tab).

Kent Waldrop Ap07

Mark's response is why I want you to post a new thread. Sorry, Mark. Should I split this thread



Re: Convert Rows into Columns... (Cross tab).

Jon Royales

Thanks for the links kent.

I have managed to solve my problem.