Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Excel Pivot tables connecting to sql

Need some help. I need to get data from sql server and create a pivot table.
Unfor, i need to have user tell what date range the pivot table to show.
I just want to know what is an easy way to make a pivot table with parameter
that is link to a view in sql

I can't bring in the data since it is more than 65k, that is why a view was
created/
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Excel Pivot tables connecting to sql

You can use build an external data query (with parameters) to import the data
into a list on a worksheet, then use the query's result range to be the data
range for the pivottable. Testing this on Excel 2000, the pivottable data
range did properly update to match the new size of the query result range but
I did have to manually refresh the pivottable after the query was rerun. You
could automate (e.g. with a Command button) so that after entering the
parameters your code would first refresh the querytable and then refresh the
pivottable.

Another option is to set up the pivottable using the full data set and then
use VBA code to modify its PivotTable.PivotCache.CommandText property, which
contains the SQL query. You could run VBA code after your users enter the
parameters so that it modifies the CommandText by substituting the new
parameter values; e.g:

Sub PivotUpdate()
Dim OldSQL as String

With Worksheets("SheetName").PivotTables(1).PivotCache
OldSQL = .CommandText ' store the unmodified query
' Next line will add a condition to the SQL query
.CommandText = Replace(.CommandText, "WHERE ", "WHERE
COL1="&Range("A1").Value
' this assumed you wanted cell A1 to be the criteria for COL1
.Refresh
.CommandText = OldSQL ' to leave it unmodified so it can be reused
End With
End Sub

Just the basics but hope you get the idea.
--
- K Dales


"Justin" wrote:

Need some help. I need to get data from sql server and create a pivot table.
Unfor, i need to have user tell what date range the pivot table to show.
I just want to know what is an easy way to make a pivot table with parameter
that is link to a view in sql

I can't bring in the data since it is more than 65k, that is why a view was
created/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting Excel sheets to Access Tables??? Dave Excel Discussion (Misc queries) 1 January 9th 09 11:44 PM
Building pivot tables in Excel 2007 based on existing pivot tables? [email protected] Excel Discussion (Misc queries) 4 December 26th 07 08:05 PM
Problem with Pivot table Connecting to SQL 2005 OLAP [email protected] Excel Discussion (Misc queries) 0 December 8th 05 04:14 PM
connecting a pivot table to a data cube in VBA Steve Excel Programming 0 November 25th 04 04:09 AM
Pivot tables-controlling user interaction with pivot tables Sindhura Excel Programming 0 August 27th 03 02:10 PM


All times are GMT +1. The time now is 09:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"