Monday, March 26, 2012

Problem with Sql Query

By Running a query, I got the result set as shown below

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 and no. of rows for Status is unknown. it may be more than three like (I, O, S, T, W and so on), so dynamically the there will be more columns.


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

RG

Reminds me of the Cross-Tab queries in MS-Access.

Check -

http://www.stephenforte.net/owdasblog/PermaLink.aspx?guid=2b0532fc-4318-4ac0-a405-15d6d813eeb8

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q175574

'Almost' dynamic column generation.

|||I believe the new pivot functionality in sql server 2005/ express will do that for ya.sql

No comments:

Post a Comment