Home All Groups Group Topic Archive Search About

Execute Stored Procedure from User Defined Function

Author
7 Oct 2005 5:12 PM
JC
Is it possible to execute a Stored Procedure from within a user defined
function.
The purpose of the user defined function is to be able to use the results of
the Stored Procedure in a select statement. The user defined function should
return a table.

Author
7 Oct 2005 5:27 PM
Jerry Spivey
JC,

Why do you need both?  Can't you just use a stored procedure?

HTH

Jerry
Show quoteHide quote
"JC" <J*@discussions.microsoft.com> wrote in message
news:009B25FA-06E1-481C-B563-6B4F3745717C@microsoft.com...
> Is it possible to execute a Stored Procedure from within a user defined
> function.
> The purpose of the user defined function is to be able to use the results
> of
> the Stored Procedure in a select statement. The user defined function
> should
> return a table.
Are all your drivers up to date? click for free checkup

Author
7 Oct 2005 6:51 PM
JC
I need to use the results of the stored procedure in an inner join.
Here is an Example:
Select *
From Table1 INNER JOIN <ResultReturnedBy_StoredProcedure> ON Table1.ID=
<ResultReturnedBy_StoredProcedure>.ID

You can use UDF functions in this manner but as far as I know I can only get
results from a Stored Procedure using the Execute statement. If there is a
another way to accomplish what I'm trying to do besides using UDF please let
me know.


Show quoteHide quote
"Jerry Spivey" wrote:

> JC,
>
> Why do you need both?  Can't you just use a stored procedure?
>
> HTH
>
> Jerry
> "JC" <J*@discussions.microsoft.com> wrote in message
> news:009B25FA-06E1-481C-B563-6B4F3745717C@microsoft.com...
> > Is it possible to execute a Stored Procedure from within a user defined
> > function.
> > The purpose of the user defined function is to be able to use the results
> > of
> > the Stored Procedure in a select statement. The user defined function
> > should
> > return a table.
>
>
>
Author
7 Oct 2005 7:12 PM
Jerry Spivey
JC,

Create a temp table, load the data into the temp table from the proc via
INSERT...EXEC, join with the temp table.

HTH

Jerry
Show quoteHide quote
"JC" <J*@discussions.microsoft.com> wrote in message
news:0DFBC2D5-87A4-4C88-A923-DA0C918749FF@microsoft.com...
>I need to use the results of the stored procedure in an inner join.
> Here is an Example:
> Select *
> From Table1 INNER JOIN <ResultReturnedBy_StoredProcedure> ON Table1.ID=
> <ResultReturnedBy_StoredProcedure>.ID
>
> You can use UDF functions in this manner but as far as I know I can only
> get
> results from a Stored Procedure using the Execute statement. If there is a
> another way to accomplish what I'm trying to do besides using UDF please
> let
> me know.
>
>
> "Jerry Spivey" wrote:
>
>> JC,
>>
>> Why do you need both?  Can't you just use a stored procedure?
>>
>> HTH
>>
>> Jerry
>> "JC" <J*@discussions.microsoft.com> wrote in message
>> news:009B25FA-06E1-481C-B563-6B4F3745717C@microsoft.com...
>> > Is it possible to execute a Stored Procedure from within a user defined
>> > function.
>> > The purpose of the user defined function is to be able to use the
>> > results
>> > of
>> > the Stored Procedure in a select statement. The user defined function
>> > should
>> > return a table.
>>
>>
>>
Author
7 Oct 2005 8:47 PM
JC
Jerry,
Thanks for your responses.
I had considered the temp table idea but was hesitant about performance. Is
performance really a concern with temp tables. Also just to know, Execute
statements are not allowed inside a UDF, Y or N?

Show quoteHide quote
"Jerry Spivey" wrote:

> JC,
>
> Create a temp table, load the data into the temp table from the proc via
> INSERT...EXEC, join with the temp table.
>
> HTH
>
> Jerry
> "JC" <J*@discussions.microsoft.com> wrote in message
> news:0DFBC2D5-87A4-4C88-A923-DA0C918749FF@microsoft.com...
> >I need to use the results of the stored procedure in an inner join.
> > Here is an Example:
> > Select *
> > From Table1 INNER JOIN <ResultReturnedBy_StoredProcedure> ON Table1.ID=
> > <ResultReturnedBy_StoredProcedure>.ID
> >
> > You can use UDF functions in this manner but as far as I know I can only
> > get
> > results from a Stored Procedure using the Execute statement. If there is a
> > another way to accomplish what I'm trying to do besides using UDF please
> > let
> > me know.
> >
> >
> > "Jerry Spivey" wrote:
> >
> >> JC,
> >>
> >> Why do you need both?  Can't you just use a stored procedure?
> >>
> >> HTH
> >>
> >> Jerry
> >> "JC" <J*@discussions.microsoft.com> wrote in message
> >> news:009B25FA-06E1-481C-B563-6B4F3745717C@microsoft.com...
> >> > Is it possible to execute a Stored Procedure from within a user defined
> >> > function.
> >> > The purpose of the user defined function is to be able to use the
> >> > results
> >> > of
> >> > the Stored Procedure in a select statement. The user defined function
> >> > should
> >> > return a table.
> >>
> >>
> >>
>
>
>
Author
7 Oct 2005 8:54 PM
Jerry Spivey
Depends on the number of records.  I don't really use UDFs too much so I
don't know the answer to the second question.

HTH

Jerry
Show quoteHide quote
"JC" <J*@discussions.microsoft.com> wrote in message
news:CB1F5B06-C152-4E0A-A565-3FDC1CA06FD8@microsoft.com...
> Jerry,
> Thanks for your responses.
> I had considered the temp table idea but was hesitant about performance.
> Is
> performance really a concern with temp tables. Also just to know, Execute
> statements are not allowed inside a UDF, Y or N?
>
> "Jerry Spivey" wrote:
>
>> JC,
>>
>> Create a temp table, load the data into the temp table from the proc via
>> INSERT...EXEC, join with the temp table.
>>
>> HTH
>>
>> Jerry
>> "JC" <J*@discussions.microsoft.com> wrote in message
>> news:0DFBC2D5-87A4-4C88-A923-DA0C918749FF@microsoft.com...
>> >I need to use the results of the stored procedure in an inner join.
>> > Here is an Example:
>> > Select *
>> > From Table1 INNER JOIN <ResultReturnedBy_StoredProcedure> ON Table1.ID=
>> > <ResultReturnedBy_StoredProcedure>.ID
>> >
>> > You can use UDF functions in this manner but as far as I know I can
>> > only
>> > get
>> > results from a Stored Procedure using the Execute statement. If there
>> > is a
>> > another way to accomplish what I'm trying to do besides using UDF
>> > please
>> > let
>> > me know.
>> >
>> >
>> > "Jerry Spivey" wrote:
>> >
>> >> JC,
>> >>
>> >> Why do you need both?  Can't you just use a stored procedure?
>> >>
>> >> HTH
>> >>
>> >> Jerry
>> >> "JC" <J*@discussions.microsoft.com> wrote in message
>> >> news:009B25FA-06E1-481C-B563-6B4F3745717C@microsoft.com...
>> >> > Is it possible to execute a Stored Procedure from within a user
>> >> > defined
>> >> > function.
>> >> > The purpose of the user defined function is to be able to use the
>> >> > results
>> >> > of
>> >> > the Stored Procedure in a select statement. The user defined
>> >> > function
>> >> > should
>> >> > return a table.
>> >>
>> >>
>> >>
>>
>>
>>
Author
7 Oct 2005 9:06 PM
JC
The temp table will consist of one int primary key column and no other
columns. It will usually have between 5K to 20K rows but in some instances it
can potentially have more.

Show quoteHide quote
"Jerry Spivey" wrote:

> Depends on the number of records.  I don't really use UDFs too much so I
> don't know the answer to the second question.
>
> HTH
>
> Jerry
> "JC" <J*@discussions.microsoft.com> wrote in message
> news:CB1F5B06-C152-4E0A-A565-3FDC1CA06FD8@microsoft.com...
> > Jerry,
> > Thanks for your responses.
> > I had considered the temp table idea but was hesitant about performance.
> > Is
> > performance really a concern with temp tables. Also just to know, Execute
> > statements are not allowed inside a UDF, Y or N?
> >
> > "Jerry Spivey" wrote:
> >
> >> JC,
> >>
> >> Create a temp table, load the data into the temp table from the proc via
> >> INSERT...EXEC, join with the temp table.
> >>
> >> HTH
> >>
> >> Jerry
> >> "JC" <J*@discussions.microsoft.com> wrote in message
> >> news:0DFBC2D5-87A4-4C88-A923-DA0C918749FF@microsoft.com...
> >> >I need to use the results of the stored procedure in an inner join.
> >> > Here is an Example:
> >> > Select *
> >> > From Table1 INNER JOIN <ResultReturnedBy_StoredProcedure> ON Table1.ID=
> >> > <ResultReturnedBy_StoredProcedure>.ID
> >> >
> >> > You can use UDF functions in this manner but as far as I know I can
> >> > only
> >> > get
> >> > results from a Stored Procedure using the Execute statement. If there
> >> > is a
> >> > another way to accomplish what I'm trying to do besides using UDF
> >> > please
> >> > let
> >> > me know.
> >> >
> >> >
> >> > "Jerry Spivey" wrote:
> >> >
> >> >> JC,
> >> >>
> >> >> Why do you need both?  Can't you just use a stored procedure?
> >> >>
> >> >> HTH
> >> >>
> >> >> Jerry
> >> >> "JC" <J*@discussions.microsoft.com> wrote in message
> >> >> news:009B25FA-06E1-481C-B563-6B4F3745717C@microsoft.com...
> >> >> > Is it possible to execute a Stored Procedure from within a user
> >> >> > defined
> >> >> > function.
> >> >> > The purpose of the user defined function is to be able to use the
> >> >> > results
> >> >> > of
> >> >> > the Stored Procedure in a select statement. The user defined
> >> >> > function
> >> >> > should
> >> >> > return a table.
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Author
30 Nov 2005 5:25 AM
Ibrahim Mesbah
I'm having the same problem.  I would like to use a UDF to call my stored
procedure so I could create a view using it.  I am developing an application
in C# that uses Crystal Reports.  It is so much easier for the Reports to use
Tables/Views/Functions (Stored Procs are not even listed) by the wizard.  Any
suggestions? 

Show quoteHide quote
"JC" wrote:

> The temp table will consist of one int primary key column and no other
> columns. It will usually have between 5K to 20K rows but in some instances it
> can potentially have more.
>
> "Jerry Spivey" wrote:
>
> > Depends on the number of records.  I don't really use UDFs too much so I
> > don't know the answer to the second question.
> >
> > HTH
> >
> > Jerry
> > "JC" <J*@discussions.microsoft.com> wrote in message
> > news:CB1F5B06-C152-4E0A-A565-3FDC1CA06FD8@microsoft.com...
> > > Jerry,
> > > Thanks for your responses.
> > > I had considered the temp table idea but was hesitant about performance.
> > > Is
> > > performance really a concern with temp tables. Also just to know, Execute
> > > statements are not allowed inside a UDF, Y or N?
> > >
> > > "Jerry Spivey" wrote:
> > >
> > >> JC,
> > >>
> > >> Create a temp table, load the data into the temp table from the proc via
> > >> INSERT...EXEC, join with the temp table.
> > >>
> > >> HTH
> > >>
> > >> Jerry
> > >> "JC" <J*@discussions.microsoft.com> wrote in message
> > >> news:0DFBC2D5-87A4-4C88-A923-DA0C918749FF@microsoft.com...
> > >> >I need to use the results of the stored procedure in an inner join.
> > >> > Here is an Example:
> > >> > Select *
> > >> > From Table1 INNER JOIN <ResultReturnedBy_StoredProcedure> ON Table1.ID=
> > >> > <ResultReturnedBy_StoredProcedure>.ID
> > >> >
> > >> > You can use UDF functions in this manner but as far as I know I can
> > >> > only
> > >> > get
> > >> > results from a Stored Procedure using the Execute statement. If there
> > >> > is a
> > >> > another way to accomplish what I'm trying to do besides using UDF
> > >> > please
> > >> > let
> > >> > me know.
> > >> >
> > >> >
> > >> > "Jerry Spivey" wrote:
> > >> >
> > >> >> JC,
> > >> >>
> > >> >> Why do you need both?  Can't you just use a stored procedure?
> > >> >>
> > >> >> HTH
> > >> >>
> > >> >> Jerry
> > >> >> "JC" <J*@discussions.microsoft.com> wrote in message
> > >> >> news:009B25FA-06E1-481C-B563-6B4F3745717C@microsoft.com...
> > >> >> > Is it possible to execute a Stored Procedure from within a user
> > >> >> > defined
> > >> >> > function.
> > >> >> > The purpose of the user defined function is to be able to use the
> > >> >> > results
> > >> >> > of
> > >> >> > the Stored Procedure in a select statement. The user defined
> > >> >> > function
> > >> >> > should
> > >> >> > return a table.
> > >> >>
> > >> >>
> > >> >>
> > >>
> > >>
> > >>
> >
> >
> >

Bookmark and Share

Post Thread options