Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Call SQL Server Stored Procedures with parameters,

We have a block of code that looks like this:

With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN= XXX",
Destination:=Range("A1"))
.CommandText = "spsReport17" ' Array("SELECT * FROM tblReport17")

.Name = "XXX"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
End With

..CommandText used to just be a 'SELECT * FROM...' statment but we are having
to change to Stored Procedures - and this worked ok.
However, we now need to pass a single parameter to this Stored Proc.

Can anybody tell me the syntax (or even if this is possible) please.
I've looked in the help and can't find anything about this.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Call SQL Server Stored Procedures with parameters,

Hi KCSL,

Yes you can call a stored procedure when creating a QueryTable, you just
have to treat the stored procedure and any arguments to it as if it were any
other SQL string. Here's an example:

Sub QueryWithStoredProc()
Dim objQT As QueryTable
Set objQT = Sheet1.QueryTables.Add("ODBC;DSN=XXX;", _
Sheet1.Range("A1"))
objQT.CommandText = "spMyStoredProc 'TextArgument'"
objQT.CommandType = xlCmdSql
objQT.Refresh False
End Sub

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"KCSL" wrote in message
...
We have a block of code that looks like this:

With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN= XXX",
Destination:=Range("A1"))
.CommandText = "spsReport17" ' Array("SELECT * FROM tblReport17")

.Name = "XXX"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
End With

.CommandText used to just be a 'SELECT * FROM...' statment but we are
having
to change to Stored Procedures - and this worked ok.
However, we now need to pass a single parameter to this Stored Proc.

Can anybody tell me the syntax (or even if this is possible) please.
I've looked in the help and can't find anything about this.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Call SQL Server Stored Procedures with parameters,

Hi,
I have a similar problem, but I can't seem to get the parameter to work. I
can run the stored procedure without any problem but I don't understand how
or what kind of text arguement is needed. Can you give an example of this?
(I have tried where clauses but they don't work)

Thanks,
Scott

"Rob Bovey" wrote:

Hi KCSL,

Yes you can call a stored procedure when creating a QueryTable, you just
have to treat the stored procedure and any arguments to it as if it were any
other SQL string. Here's an example:

Sub QueryWithStoredProc()
Dim objQT As QueryTable
Set objQT = Sheet1.QueryTables.Add("ODBC;DSN=XXX;", _
Sheet1.Range("A1"))
objQT.CommandText = "spMyStoredProc 'TextArgument'"
objQT.CommandType = xlCmdSql
objQT.Refresh False
End Sub

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"KCSL" wrote in message
...
We have a block of code that looks like this:

With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN= XXX",
Destination:=Range("A1"))
.CommandText = "spsReport17" ' Array("SELECT * FROM tblReport17")

.Name = "XXX"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
End With

.CommandText used to just be a 'SELECT * FROM...' statment but we are
having
to change to Stored Procedures - and this worked ok.
However, we now need to pass a single parameter to this Stored Proc.

Can anybody tell me the syntax (or even if this is possible) please.
I've looked in the help and can't find anything about this.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Call SQL Server Stored Procedures with parameters,

Hi Scott,

I'm not totally sure what you're looking for. I've shown an example
below that calls a stored procedure and passes it one text argument. I've
hard-coded the argument value in this case in order to make the syntax more
clear, but it could just as easily have been specified using a variable or a
cell reference.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Scott" wrote in message
...
Hi,
I have a similar problem, but I can't seem to get the parameter to work.
I
can run the stored procedure without any problem but I don't understand
how
or what kind of text arguement is needed. Can you give an example of
this?
(I have tried where clauses but they don't work)

Thanks,
Scott

"Rob Bovey" wrote:

Hi KCSL,

Yes you can call a stored procedure when creating a QueryTable, you
just
have to treat the stored procedure and any arguments to it as if it were
any
other SQL string. Here's an example:

Sub QueryWithStoredProc()
Dim objQT As QueryTable
Set objQT = Sheet1.QueryTables.Add("ODBC;DSN=XXX;", _
Sheet1.Range("A1"))
objQT.CommandText = "spMyStoredProc 'TextArgument'"
objQT.CommandType = xlCmdSql
objQT.Refresh False
End Sub

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"KCSL" wrote in message
...
We have a block of code that looks like this:

With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN= XXX",
Destination:=Range("A1"))
.CommandText = "spsReport17" ' Array("SELECT * FROM
tblReport17")

.Name = "XXX"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
End With

.CommandText used to just be a 'SELECT * FROM...' statment but we are
having
to change to Stored Procedures - and this worked ok.
However, we now need to pass a single parameter to this Stored Proc.

Can anybody tell me the syntax (or even if this is possible) please.
I've looked in the help and can't find anything about this.







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
Pivotcharts and stored procedures omar_aa Charts and Charting in Excel 5 October 9th 08 02:35 AM
Can I import SQL Stored Procedures into Excel? Nick Gill Excel Discussion (Misc queries) 0 September 11th 08 11:42 AM
Running sql stored procedures from Excel in-over-his-head-bill Excel Discussion (Misc queries) 0 July 5th 06 06:30 PM
Stored Procedures - First Attempt Jim Heavey Excel Programming 4 February 7th 06 11:10 PM
Stored Procedure call and passing parameters TLowe Excel Programming 3 April 23rd 04 10:09 AM


All times are GMT +1. The time now is 12:41 PM.

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

About Us

"It's about Microsoft Excel"