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

Posted on 2009-02-16
Medium Priority
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 ?
Question by:Tapan Pattanaik
  • 2
  • 2
  • 2
LVL 93

Accepted Solution

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.
LVL 39

Assisted Solution

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 
select dbo.SomeFunction() as UDFValue

Open in new window

LVL 22

Author Comment

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

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

As Brandon and I both stated above, yes.


LVL 22

Author Closing Comment

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

Expert Comment

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.

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