Question

My "FeedbackSummary" table structure is

GivenBy varchar(50)
GivenTo varchar(50)
Points  decimal(15, 2)

Sample Data

Alice   Janet   4.50
Alice   Bruce   3.50
Bruce   Alice   2.87
Bruce   Janet   4.75
Janet   Alice   5.45
Janet   Bruce   3.78

What I am trying to achieve

GivenBy_GivenTo Alice   Bruce   Janet
Alice           NULL    3.50    4.50    
Bruce           2.87    NULL    4.75
Janet           5.45    3.78    NULL

Platform: SQL Server 2005 & 2008

How this can be done using Pivot or any other techniques. Can this be achieved using SQL Reporting Services easily?

Thanks in advance.

Was it helpful?

Solution

Best is to use SSRS. Put a matrix there, with one column on the rows and one on the columns. You can pivot in a query (the PIVOT option), but that doesn't allow for flexibility in reporting.

Rob

OTHER TIPS

  SELECT t.givenby,
         SUM(CASE WHEN t.givento = 'Alice' THEN t.points ELSE NULL END) 'Alice',
         SUM(CASE WHEN t.givento = 'Bruce' THEN t.points ELSE NULL END) 'Bruce',
         SUM(CASE WHEN t.givento = 'Janet' THEN t.points ELSE NULL END) 'Janet'
    FROM TABLE t
GROUP BY t.givenby
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top