Unix Technical Forum

Nesting a SP within another SP?

This is a discussion on Nesting a SP within another SP? within the SQL Server forums, part of the Microsoft SQL Server category; --> I have a stored procedure that calls some UDF User Defined Functions, the purpose of which is to create ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 07:44 PM
Lauren Quantrell
 
Posts: n/a
Default Nesting a SP within another SP?

I have a stored procedure that calls some UDF User Defined Functions,
the purpose of which is to create row strings out of numerous column
strings for matching uniqueIDs.

The problem is I need to join that SP with some other tables.

The SP I have reads something like:

mySPName
@myUserID int
SELECT myUniqueID, dbo.fn_myFunctionName(UniqueID) As myRunningString
FROM myTEMPTableName
GROUP BY myUniqueID
WHERE myTEMPTableName.UserID = @myUserID

I need to join that result with myTableName on myUniqueID such as:
Select myTableName.myField1, myTableName.myField2,
mySPName.myRunningString
From ...
-- joining myTableName.myUniqueID = mySPName.myUniqueID

Can this be done?
The reason I don't just do it with a View instead of an SP is that I
have that parameter that must be passed to filter the records in
myTEMPTableName.

Any help is appreciated.
lq

oh...
the UDF looks like:

Create Function dbo.fn_myFunctionName(@myUniqueID as int) returns
nvarchar(500)
AS
BEGIN
DECLARE @ret_value nvarchar(500)
SET @ret_value=''
SELECT @ret_value=@ret_value + ';' + myString
FROM myTEMPTableName
WHERE
myUniqueID =@myUniqueID
RETURN RIGHT(@ret_value,Len(@ret_value)-2)
END
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 07:44 PM
Simon Hayes
 
Posts: n/a
Default Re: Nesting a SP within another SP?

laurenquantrell@hotmail.com (Lauren Quantrell) wrote in message news:<47e5bd72.0401272245.449a0756@posting.google. com>...
> I have a stored procedure that calls some UDF User Defined Functions,
> the purpose of which is to create row strings out of numerous column
> strings for matching uniqueIDs.
>
> The problem is I need to join that SP with some other tables.
>
> The SP I have reads something like:
>
> mySPName
> @myUserID int
> SELECT myUniqueID, dbo.fn_myFunctionName(UniqueID) As myRunningString
> FROM myTEMPTableName
> GROUP BY myUniqueID
> WHERE myTEMPTableName.UserID = @myUserID
>
> I need to join that result with myTableName on myUniqueID such as:
> Select myTableName.myField1, myTableName.myField2,
> mySPName.myRunningString
> From ...
> -- joining myTableName.myUniqueID = mySPName.myUniqueID
>
> Can this be done?
> The reason I don't just do it with a View instead of an SP is that I
> have that parameter that must be passed to filter the records in
> myTEMPTableName.
>
> Any help is appreciated.
> lq
>
> oh...
> the UDF looks like:
>
> Create Function dbo.fn_myFunctionName(@myUniqueID as int) returns
> nvarchar(500)
> AS
> BEGIN
> DECLARE @ret_value nvarchar(500)
> SET @ret_value=''
> SELECT @ret_value=@ret_value + ';' + myString
> FROM myTEMPTableName
> WHERE
> myUniqueID =@myUniqueID
> RETURN RIGHT(@ret_value,Len(@ret_value)-2)
> END


There are some options described here:

http://www.sommarskog.se/share_data.html

From your description, rewriting the stored procedure as a
table-valued UDF sounds like it should be possible.

Simon
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

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


All times are GMT. The time now is 10:38 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com