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

Posted on 2009-02-16
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
    LVL 92

    Accepted Solution

    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

    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 20

    Author Comment

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

    LVL 92

    Expert Comment

    by:Patrick Matthews

    As Brandon and I both stated above, yes.


    LVL 20

    Author Closing Comment

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

    Expert Comment

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now