|
Hi All, Please help me with the below mentioned Scenario-> Scenario-> I have table named as cricket wherein columns are (cric_id int identity,nation varchar(20),Format varchar(20),Rank int) Data is -> Now I need to generate a Report in ASP.NET C# where i need a data in format given below Nation,Rank,IPL,ODI,TEST,T20... and so on I mean i need to dynamically generate a report by transposing rows of column format.So If I add a new value in format column , It should be displayed as a column in my Report Immediate response will be much appreciated Thanks in Advance
(comments are locked)
|
|
I beleive this could be handled by Dynamic query instead of CURSORs. Thnx usman!!
Jan 17 '12 at 12:54 AM
innovator
@Navin19 Did you award me the points intentionally? These points are actually deducted from your own pool, and transferred to me. If you wanted to mark my answer as accepted, then you should have clicked the tick sign :)
Jan 17 '12 at 01:56 AM
Usman Butt
(comments are locked)
|
|
I'd say this is a task for PIVOT, no need for dynamic sql or cursors. The "fishy" part is that pivot needs an aggregate function and you have scalar values that you want to display. But from what I can see, the values are unique, so using MAX or another aggregate function on the scalar values won't make a difference. I assume that the different formats are known beforehand. If they are not, dynamic SQL will be the thing to use: Still no need for cursors. I thought of hard-coding IPL, TEST etc as well, but then thought it is a sample data and in future may be a new format could be added as well. So, went for the dynamic query. As far as PIVOT and AGGREGATED CASE are concerned, please have a look at this
Jan 17 '12 at 01:14 AM
Usman Butt
ok! Thnkx for the comment!
Jan 17 '12 at 01:28 AM
innovator
(comments are locked)
|
|
In SQL have many way's to achieve your requirement e.g. CASE statement, PIVOT etc. For your requirement PIVOT will be the better choice if you have SQL Server 2005 or 2008.
Thnx amardeep!
Jan 17 '12 at 12:54 AM
innovator
(comments are locked)
|

