Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Joining SQL Server Stored Procedure to SQL Server Table

Is this possible? e.g.

This code executes a stored procedure with one argument for "Customer Type"
EXECUTE dbo.mysp.spname @cust_type = 'A'

1. How can I store the value for Customer Type in a cell to update the sp at
runtime?

2. How can I link the sp to another SQL Server table (e.g. to get Customer
name?) e.g.
SELECT n.cust_name FROM dbo.cust_names as n
JOIN (the stored procedure as s) ON s.cust_id = n.cust_id

3. How do I execute this?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Joining SQL Server Stored Procedure to SQL Server Table


Range("A1").Value = "A"
' Worksheets("Sheet1").Range("A1").Value = "A"
' Sheet1.Range("A1").Value = "A"
' ThisWorkbook.Names("SomeNamedCell").RefersToRange. Value = "A"

Dim cmdText as String
cmdText = "EXECUTE dbo.mysp.spname @cust_type = '" & Range("A1").Value & "'"

Don't forget to double the single quotes if @cust_type is a varchar and
might
have single quotes in it, so revise the last statement:

cmdText = "EXECUTE dbo.mysp.spname @cust_type = '" &
Replace(Range("A1"),"'","''").Value & "'"

AFAIK you cannot join to a stored proc as you prototyped. But you can use a
user defined table function which accepts parameters and can be used inline
as a regular table.
Here is an example.
http://www.sqlteam.com/article/user-defined-functions

But do you need to do it that way? Another way is to modify your SQL a
bit...imagining your table structu

CREATE PROCEDURE spname
(
@cust_type VARCHAR(10)
)
AS
SELECT
n.cust_name
FROM dbo.cust_names n
INNER JOIN dbo.cust c
ON n.cust_id = c.cust_id
WHERE c.cust_type = @cust_type


--
Tim Zych
http://www.higherdata.com
Workbook Compare - free and pro versions


"JimP" wrote in message
...
Is this possible? e.g.

This code executes a stored procedure with one argument for "Customer
Type"
EXECUTE dbo.mysp.spname @cust_type = 'A'

1. How can I store the value for Customer Type in a cell to update the sp
at runtime?

2. How can I link the sp to another SQL Server table (e.g. to get Customer
name?) e.g.
SELECT n.cust_name FROM dbo.cust_names as n
JOIN (the stored procedure as s) ON s.cust_id = n.cust_id

3. How do I execute this?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Joining SQL Server Stored Procedure to SQL Server Table

All good ideas - thank you.


"Tim Zych" <tzych@nospam at earthlink dot net wrote in message
...

Range("A1").Value = "A"
' Worksheets("Sheet1").Range("A1").Value = "A"
' Sheet1.Range("A1").Value = "A"
' ThisWorkbook.Names("SomeNamedCell").RefersToRange. Value = "A"

Dim cmdText as String
cmdText = "EXECUTE dbo.mysp.spname @cust_type = '" & Range("A1").Value &
"'"

Don't forget to double the single quotes if @cust_type is a varchar and
might
have single quotes in it, so revise the last statement:

cmdText = "EXECUTE dbo.mysp.spname @cust_type = '" &
Replace(Range("A1"),"'","''").Value & "'"

AFAIK you cannot join to a stored proc as you prototyped. But you can use
a user defined table function which accepts parameters and can be used
inline as a regular table.
Here is an example.
http://www.sqlteam.com/article/user-defined-functions

But do you need to do it that way? Another way is to modify your SQL a
bit...imagining your table structu

CREATE PROCEDURE spname
(
@cust_type VARCHAR(10)
)
AS
SELECT
n.cust_name
FROM dbo.cust_names n
INNER JOIN dbo.cust c
ON n.cust_id = c.cust_id
WHERE c.cust_type = @cust_type


--
Tim Zych
http://www.higherdata.com
Workbook Compare - free and pro versions


"JimP" wrote in message
...
Is this possible? e.g.

This code executes a stored procedure with one argument for "Customer
Type"
EXECUTE dbo.mysp.spname @cust_type = 'A'

1. How can I store the value for Customer Type in a cell to update the sp
at runtime?

2. How can I link the sp to another SQL Server table (e.g. to get
Customer
name?) e.g.
SELECT n.cust_name FROM dbo.cust_names as n
JOIN (the stored procedure as s) ON s.cust_id = n.cust_id

3. How do I execute 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
SQL Server Stored Procedure JimP Excel Programming 5 March 7th 09 12:22 PM
Calling a Stored procedure on SQL Server asynchronously INTP56 Excel Programming 1 July 27th 07 05:01 PM
Run SQL Server stored procedure in Excel macro Peder Myhre Excel Programming 1 November 8th 05 10:54 PM
pass paramter to SQL server stored procedure Souris Excel Programming 1 October 22nd 05 11:47 AM
Importing Data from a Stored Procedure (SQL SErver) Martin Eckart Excel Programming 1 January 22nd 04 01:24 AM


All times are GMT +1. The time now is 04:42 AM.

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"