?
Solved

Can we execute user defined function inside stored procedure in ms sql server?

Posted on 2009-02-16
7
Medium Priority
?
1,252 Views
Last Modified: 2012-05-06
Can we execute user defined function inside stored procedure in ms SQL server?

if yes, can u give a example? Is there any adverse effect ?
0
Comment
Question by:Tapan Pattanaik
  • 2
  • 2
  • 2
6 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 260 total points
ID: 23652301
You do not execute a UDF; you use it in expressions, including within queries, views, and sprocs.

As for adverse effects, compared to native SQL, UDFs run much slower, so if you can get the same result
using native SQL, you will get better performance.
0
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 240 total points
ID: 23652307
There are two types of UDFs.  Scalar and Table valued.


The example of a scalar valued function would be.


select dbo.SomeFunction()

An example of a Table valued function would be.

select SomeValue from dbo.SomeFunction()


You can call it like any other SQL.
create procedure up_SomeProcedure 
as
 
select dbo.SomeFunction() as UDFValue

Open in new window

0
 
LVL 22

Author Comment

by:Tapan Pattanaik
ID: 23656603
Can we use user defined function inside stored procedure in ms sql server?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 23658924
tapanpattanaik,

As Brandon and I both stated above, yes.

Regards,

Patrick
0
 
LVL 22

Author Closing Comment

by:Tapan Pattanaik
ID: 31547432
I am new to this subject, so i accept your comment as my solution
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 23663439
While you may not have gotten the answer you desired, it is 100% correct and a B is not an appropriate answer.  I would ask that you "request attention" and have the grade changed.  Request Attention can be found in your original post.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
What we learned in Webroot's webinar on multi-vector protection.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question