Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2007, 10:43 PM
Authorized User
 
Join Date: Oct 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Server Crosstab Query

Hi,

Can anynone help me create a crosstab query in SQL Server?
My table structure is:

projectID batchCode weekNo CompletionAverage
   1 a1 1 10
   1 a1 2 12
   1 a1 3 25
   2 a1 1 20
   2 a1 2 30

I would want to have a crosstab query similar to the one below:

projectID batchCode 1 2 3
   1 a1 10 12 25
   2 a1 20 30

I would like the records to be arranged by projectID with weekNo as the columns. The number of records for each project is indefinite which means the number of columns would be indefinite too. I can easily create this in Access, but I guess there's no TRANSFORM statement in SQL Server 2000. I hope you can help me solve this problem. Thanks very much!

 
Old May 4th, 2007, 01:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Google for "Dynamic crosstab queries", that should help you.

_________________________
- Vijay G
Strive for Perfection
 
Old May 5th, 2007, 11:57 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

I'd say, especially since the number of columns is "indefinite", that you should create a spreasheet that uses an "External data source" to create a "pivot" table... "Pivot" and "CrossTab" are nearly synonomous.

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
crosstab query and asp tulincim Classic ASP Databases 0 September 13th, 2005 03:00 PM
Crosstab Query Ben Access 7 November 22nd, 2004 06:08 AM
Crosstab query Berni016x SQL Server 2000 2 September 17th, 2004 10:43 AM
Crosstab query in SQL Server Dhodie SQL Server 2000 3 June 17th, 2004 08:53 PM
Crosstab query vladimir Access 1 December 1st, 2003 04:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.