Home All Groups Group Topic Archive Search About

Inline user-defined function

Author
26 Aug 2005 10:39 AM
CodeRazor
Hi,
I am trying to create an inline user-defined function.
The code below works fine, however I want to be able to put an "If else"
statement in it, so that depending on the @variable entered,  a different
Select clause will execute.

How can I put an If Else clause within the code below? I keep getting errors.

CREATE FUNCTION csp_InlineFunction
( @variable INT )
RETURNS TABLE
AS
RETURN (
    SELECT * FROM Northwind       
       )
GO


Many thanks,

CodeRazor

Author
26 Aug 2005 11:06 AM
Tibor Karaszi
You can't. Inline table valued function are handled very similar to views, very efficiently, and
they can be handled that efficiently just because they contain on only one SELECT statement. Perhaps
you can tweak the one SELECT statement depending on the variable, hard for us to tell. Or use a
multi statement table valued function.

Show quote
"CodeRazor" <CodeRa***@discussions.microsoft.com> wrote in message
news:07C1E0DA-52D8-4987-8688-E480B802E0A8@microsoft.com...
> Hi,
> I am trying to create an inline user-defined function.
> The code below works fine, however I want to be able to put an "If else"
> statement in it, so that depending on the @variable entered,  a different
> Select clause will execute.
>
> How can I put an If Else clause within the code below? I keep getting errors.
>
> CREATE FUNCTION csp_InlineFunction
> ( @variable INT )
> RETURNS TABLE
> AS
> RETURN (
> SELECT * FROM Northwind
>       )
> GO
>
>
> Many thanks,
>
> CodeRazor
Author
26 Aug 2005 11:15 AM
CodeRazor
thank you Tibor. YOu've helped me out.

CR

AddThis Social Bookmark Button