Link to home
Start Free TrialLog in
Avatar of patrikmichnac
patrikmichnac

asked on

pivot table

I need result from one table as SQL select. I am using SQLEXPRESS 2005. I need something look like pivot table in MS EXCEL.

data for example

name       time        part
john           10           I.
mike            5           II.
candy          7           I.
mike             13          III.
john            10          I.
candy           6            II.
leo                 8           III.

and I need SQL select result order by part total descending

name        part I.         part II.               part III.     part total
john            20              0                       0               20
mike            0                5                      13             18
candy         7                 6                      0                13
leo               0                0                       8                8




ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of patrikmichnac
patrikmichnac

ASKER

Hello Patrick

Thank you for your quick answer. I try to run your script by SQL Manager 2008 for SQL Server. I got this error. Error converting data type varchar to bigint.

My data has this sctructure: name is varchar, time is bigint and part is char.

any reason plase?
patrikmichnac,

You accepted the answer; is there still a problem, or did you figure it out?

Not sure where the error came from.  When I tested it, I had [name] and [part] both as
varchar(50), and [time] as int.

Regards,

Patrick