Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 November 16th, 2003, 11:39 PM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert 2-D pivot table into a regular recordset ?

How can I insert pivot table data into a regular ado recordset?

The pivot table would have just to dimensions.

Currently, we use ADO pass through SQL on an Access97 database, which works
fine, but we want to move it to SQL Server 2000.

For example:
source table:
[Country], [Amount Raised], [Date]
Germany $100 2001
Germany $100 2000
France $120 2000

pivot table:
          2000 2001
Germany $100 $100
France $100 $0

(Sorry if the pivot table formatting is off )

Thanks in advance for your help,

Eric



 
Old November 17th, 2003, 08:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

This is the one area where Access does it better than SQL Server. SQL Server does not provide the TRANSFORM...PIVOT command (which is not SQL Standard). To do this in standard SQL requires use of the CASE expression, as:
Code:
SELECT Country,
    SUM(CASE WHEN [Date]='2000' THEN [Amount Raised] ELSE 0 END) as Amount2000,
    SUM(CASE WHEN [Date]='2001' THEN [Amount Raised] ELSE 0 END) as Amount2001
FROM yourTable
GROUP BY Country
P.S. Don't use "Date" as a column name. It's just not a helpful name (what date?). (especially when your data values aren't a date) :)

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table vbsolo Excel VBA 3 November 23rd, 2005 01:28 AM
insert into new table from recordset bleutiger Classic ASP Databases 4 February 23rd, 2005 05:07 AM
Pivot Table mikeparams SQL Server 2000 1 February 9th, 2005 10:10 AM
Pivot Table ramdasu Excel VBA 0 October 23rd, 2003 03:16 AM
Pivot Table integrity cmquinn Excel VBA 0 June 23rd, 2003 06:25 AM





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