error in user defined function?

error in user defined function?

Post by Kristofer Gafver » Mon, 25 Aug 2003 01:06:43



Is there any way to return an error from a user defined function? Say that i
have this:


RETURNS nchar(10)
AS
BEGIN

       /* do something */

      /*do something else */
    ELSE
       /* Error, invalid param, do not run the function */
END

I hope you get the idea. They used an invalid value for a param, and the
function should not execute.

Oh, and by the way... there is a nice typo for RAISERROR if you try to use
it in a function.
"Server: Msg 443, Level 16, State 2, Procedure doNothing, Line 11
Invalid use of 'RAISEERROR' within a function."

Didn't even know RAISEERROR existed :-)

--
Regards,
Kristofer Gafvert
http://www.ilopia.com - My personal Web Site, with information about things
i find interesting, for example Windows Server 2003.
Reply to newsgroup only. Remove NEWS if you must reply by email, but please
do not.

 
 
 

error in user defined function?

Post by John Bel » Mon, 25 Aug 2003 11:49:46


Hi

The only method that may make sense for a scalar function would be to return
a specific value that indicates and error


RETURNS nchar(10)
AS
BEGIN

       RETURN 'B'

       RETURN 'A'

   RETURN 'Error!!!'
END

SELECT Col1, dbo.doNothing(Col1)
FROM ( SELECT 'A' AS Col1 UNION ALL SELECT 'B' UNION ALL SELECT 'C' ) A

SELECT Col1, dbo.doNothing(Col1)
FROM ( SELECT 'A' AS Col1 UNION ALL SELECT 'B' UNION ALL SELECT 'C' ) A
WHERE dbo.doNothing(Col1) != 'Error!!!'

John


> Is there any way to return an error from a user defined function? Say that
i
> have this:


> RETURNS nchar(10)
> AS
> BEGIN

>        /* do something */

>       /*do something else */
>     ELSE
>        /* Error, invalid param, do not run the function */
> END

> I hope you get the idea. They used an invalid value for a param, and the
> function should not execute.

> Oh, and by the way... there is a nice typo for RAISERROR if you try to use
> it in a function.
> "Server: Msg 443, Level 16, State 2, Procedure doNothing, Line 11
> Invalid use of 'RAISEERROR' within a function."

> Didn't even know RAISEERROR existed :-)

> --
> Regards,
> Kristofer Gafvert
> http://www.ilopia.com - My personal Web Site, with information about
things
> i find interesting, for example Windows Server 2003.
> Reply to newsgroup only. Remove NEWS if you must reply by email, but
please
> do not.


 
 
 

error in user defined function?

Post by Kristofer Gafver » Mon, 25 Aug 2003 12:38:49


Thanks!

--
Regards,
Kristofer Gafvert
http://www.ilopia.com - My personal Web Site, with information about things
i find interesting, for example Windows Server 2003.
Reply to newsgroup only. Remove NEWS if you must reply by email, but please
do not.


> Hi

> The only method that may make sense for a scalar function would be to
return
> a specific value that indicates and error


> RETURNS nchar(10)
> AS
> BEGIN

>        RETURN 'B'

>        RETURN 'A'

>    RETURN 'Error!!!'
> END

> SELECT Col1, dbo.doNothing(Col1)
> FROM ( SELECT 'A' AS Col1 UNION ALL SELECT 'B' UNION ALL SELECT 'C' ) A

> SELECT Col1, dbo.doNothing(Col1)
> FROM ( SELECT 'A' AS Col1 UNION ALL SELECT 'B' UNION ALL SELECT 'C' ) A
> WHERE dbo.doNothing(Col1) != 'Error!!!'

> John



> > Is there any way to return an error from a user defined function? Say
that
> i
> > have this:


> > RETURNS nchar(10)
> > AS
> > BEGIN

> >        /* do something */

> >       /*do something else */
> >     ELSE
> >        /* Error, invalid param, do not run the function */
> > END

> > I hope you get the idea. They used an invalid value for a param, and the
> > function should not execute.

> > Oh, and by the way... there is a nice typo for RAISERROR if you try to
use
> > it in a function.
> > "Server: Msg 443, Level 16, State 2, Procedure doNothing, Line 11
> > Invalid use of 'RAISEERROR' within a function."

> > Didn't even know RAISEERROR existed :-)

> > --
> > Regards,
> > Kristofer Gafvert
> > http://www.ilopia.com - My personal Web Site, with information about
> things
> > i find interesting, for example Windows Server 2003.
> > Reply to newsgroup only. Remove NEWS if you must reply by email, but
> please
> > do not.