Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivoting data

Status
Not open for further replies.

mkal

Programmer
Jun 24, 2003
223
US
I have some data that looks like this:
ID NAME COUNT PRODUCTNAME
1 Tom's Garage 5 Brakes
1 Tom's Garage 3 Tail Lights
1 Tom's Garage 3 Mufflers
1 Tom's Garage 2 Spark Plugs
1 Tom's Garage 1 Oil Filters

Needs to look like this
ID NAME COUNT1 PRODUCT1 COUNT2 PRODUCT2 COUNT3 PRODUCT3 COUNT4 PRODUCT4 COUNT5 PRODUCT5
1 Tom's Garage 5 Brakes 3 Tail Lights 3 Mufflers 2 Spark Plugs 1 Oil Filters

I know there is a PIVOT function in SQL 2005 that I have been trying to use but I have been unsuccessful in getting it to work. Any help would be appreciated.

Thanks
 
code snippet from part of a query I run regularly in case it helps you:
Code:
PIVOT
(
  count(b.[category])
  FOR b.[category] IN ([0],[1],[2],[3])
)
AS p
How about that?

Fee

"The cure for anything is salt water – sweat, tears, or the sea." Isak Dinesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top