If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Executing Stored Procedures Within MS Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-04, 01:36
shlomi_salmi shlomi_salmi is offline
Registered User
 
Join Date: Feb 2004
Posts: 4
Question Executing Stored Procedures Within MS Query

Hi Everyone...


I'm trying to retrieve data from Microsoft SQL Server To Microsoft Excel using MS Query (MSQRY32.EXE).

I want my end user to be able to change parameters in the query.
When I use parameters in the where clause (for example: WHERE XXX=?) I get the data succesfully, BUT when I try to use parameters in Stored Procedurs I always get the same message : "Parameters are not allowed in queries that can't be displayed graphically".

I tried MS Query Help, and it says I supose to run the procedure with hard coded values instead of parameters, save it, and then change the parameters to "?" (See image for details), BUT I GET THE SAME MESSAGE...

If anybody can help, i will appreciate it.

Thanks
Reply With Quote
  #2 (permalink)  
Old 02-19-04, 05:30
qha_vn qha_vn is offline
Registered User
 
Join Date: Jan 2003
Location: Vietnam
Posts: 188
simply design your query to get its parameters' value from cells in the worksheet and let your end users change the value of those cells
__________________
qha_vn
Reply With Quote
  #3 (permalink)  
Old 02-19-04, 10:37
shlomi_salmi shlomi_salmi is offline
Registered User
 
Join Date: Feb 2004
Posts: 4
Red face thanks, but that's not my problem

i can't change the parameters in the query if the query is a stored procedure. when i use a simple query my end users can change the parameters, but in SP's it saves the query WITH the parameters...
Reply With Quote
  #4 (permalink)  
Old 03-10-04, 21:47
grrr223 grrr223 is offline
Registered User
 
Join Date: Feb 2004
Posts: 126
Maybe this will help, I'm using a table-valued function, but it's the same concept:

Code:
Sub InsertParameterizedData()

    With ActiveSheet.QueryTables.Add(Connection:=Array( _
        "OLEDB;Provider=SQLOLEDB.1;Persist Security Info=True;Initial Catalog=DatabaseName;Data Source=ServerName;Use Proc" _
        , _
        "edure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with colu" _
        , "mn collation when possible=False"), Destination:=ActiveCell.Range("A2"))
        .CommandType = xlCmdSql
        .CommandText = Array( _
        "SELECT * FROM DatabaseName.dbo.fnConsolidatedInvoices(" & ActiveCell & "," & ActiveCell.Range("B1") & ")")
        .Name = "NameYourQueryTableHere"
        .Refresh BackgroundQuery:=False
    End With
End Sub
The macro above returns the data from fn.ConsolidateInvoices(@StartDate,@EndDate) where I have replaced the parameter values with the value in the ActiveCell and the cell to the right of it.

It then places the data beginning on the cell one row below the ActiveCell.

I got all this using the Macro Recorder (God's gift to those of us unfortunate enough to work with Excel on a regular basis).

Let me know if you still need any help on this.

You can actually replace the "SELECT *..." with any SQL statement you want, and concatenate the cell addresses of the parameters you want, it's pretty damned cool if you ask me.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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