Results 1 to 6 of 6

Thread: Raiserror

  1. #1
    Join Date
    Jan 2004
    Posts
    3

    Unanswered: Raiserror

    Is there a way to raise an exception inside a user function in the Sqlserver2000?.

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Guess not

    Did you check out BOL for specifics?

    Code:
    CREATE FUNCTION udf_myFunction99 (@x varchar(8000))
    RETURNS int
    AS
    BEGIN
    	RAISERROR 50001  'Error Raised'
    RETURN -1
    END
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Jan 2004
    Posts
    3
    Originally posted by Brett Kaiser
    Guess not

    Did you check out BOL for specifics?

    Code:
    CREATE FUNCTION udf_myFunction99 (@x varchar(8000))
    RETURNS int
    AS
    BEGIN
    	RAISERROR 50001  'Error Raised'
    RETURN -1
    END
    GO
    I got the error

    Server: Msg 443, Level 16, State 2, Procedure udf_myFunction99, Line 5
    Invalid use of 'RAISEERROR' within a function.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Yeah, I know...That's why I said:

    "guess not"

    Check out books online for a better description of Functions...

    I know there a few limitations...

    What are you trying to do?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Jan 2004
    Posts
    3
    Originally posted by Brett Kaiser
    Yeah, I know...That's why I said:

    "guess not"

    Check out books online for a better description of Functions...

    I know there a few limitations...

    What are you trying to do?

    There are many limitations I know, but this one I didn't found.
    I supose it΄s not allowed to use RAISERROR in functions.
    I am generating a calc module from a CASE system using only functions. So far I found a solution for every limitation. Otherwise I will have to rebuild the entire system using only stored procedure instead of functions.

    That1s why I am looking for some "magic" to raise the exception.

    Thank You.

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    ...or we could hope for a miracle...

    Since you haven't been able to raise out in the other functions, why do you want to with this one?

    And yeah, sprocs would have been the way to go (MOO)...how are you using the functions?

    BOL

    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.
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •