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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivot Query SQL Server 2005

Status
Not open for further replies.

JohnCaver

Programmer
Joined
May 3, 2007
Messages
10
Location
GB
Hi,
I am recording results of matches between various teams in various tournaments.
My columns for the score table are HomeTeam, AwayTeam, Tournament, HomePoints, AwayPoints.

e.g.
HomeTeam|AwayTeam|Tournament|PointsHome|PointsAway
----------------------------------------------------------
A B T1 1 2
A B T2 3 4

I want to pivot this to produce a table like:

HomeTeam|AwayTeam|T1_HomePoints|T1_AwayPoints|T2_HomePoints|T2_AwayPoints
------------------------------------------------------------------------------------
A B 1 2 3 4

Can this be done in SQL Server 2005?

Thanks
 
If you click the FAQs button at the top of this forum, it will bring up a list of member-written FAQ's for SQL Server. There are a couple for creating Crosstab queries. Also, SQL Server 2005 does have some functionality for this. See the following link:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top