Convert Compex Stored Procedure to UDF

Posted on 2006-05-11
Last Modified: 2011-09-20
When I try to convert this entire stored proc to a UDF, I get's not liking the params or something.

I need to know how to transform this (a little hand holding from ground up) on how to transform this code into a UDF so I can reuse
Question by:dba123
    LVL 142

    Accepted Solution

    there are 2 things:

    * getdate()
       you cannot use getdate() inside the function, you have to pass that value are argument

    * DROP /CREATE TABLE #CurrentMonthCollections_IL_FeeBased

      you cannot use temp tables in functions, you can however use table variables instead (you can remove the DROP TABLE entirely):

       DECLARE @CurrentMonthCollecitons_IL_FeeBased TABLE ( ..< field definitions go here > .. )

    LVL 75

    Assisted Solution

    by:Aneesh Retnakaran
    1 GetDate () we can pass thru as an argument, that we can handle
    2. You can't call delete inside a function to delete the contents of tables
    3. You are not supposed to call extended procedures
    4. As  Angel memntioned, you can't DROP /CREATE TABLE

    Only these operations are permitted inside a function
    The following statements are allowed in the body of a multi-statement function. Statements not in this list are not allowed in the body of a function:

    Assignment statements.

    Control-of-Flow statements.

    DECLARE statements defining data variables and cursors that are local to the function.

    SELECT statements containing select lists with expressions that assign values to variables that are local to the function.

    Cursor operations referencing local cursors that are declared, opened, closed, and deallocated in the function. Only FETCH statements that assign values to local variables using the INTO clause are allowed; FETCH statements that return data to the client are not allowed.

    INSERT, UPDATE, and DELETE statements modifying table variables local to the function.

    EXECUTE statements calling an extended stored procedures


    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    I recently came across an interesting Question In EE ( and was puzzled about how to achieve that using SSIS out of the box tasks, which was i…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    728 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

    19 Experts available now in Live!

    Get 1:1 Help Now