|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Inline user-defined functionI 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 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 quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ Blog: http://solidqualitylearning.com/blogs/tibor/ "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 |
|||||||||||||||||||||||