Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Table valued inline function syntax
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01592983
Message ID:
01592984
Views:
44
Hi Rollin,

You cannot use BEGIN TRY.... END TRY and EXECUTE inside function.

MartinaJ

>I am trying to pass 4 variables into a table valued function, perform a select statement and have it return the results. the variables are the
>column name, table name, index name, and index value. I cant seem to get the syntax right.
>
>
>CREATE FUNCTION LOOKUP_SDL
>(
>   @COLUMN_NAME   VARCHAR(500),
>   @TABLE_NAME    VARCHAR(500),
>   @IND_NAME    VARCHAR(500),
>   @IND_VALUE    VARCHAR(500)
>)
>RETURNS TABLE
>AS
>RETURN 
>(
>   DECLARE @Stmt  VARCHAR(500);
>   SET @Stmt = ('SELECT '+@COLUMN_NAME+' FROM '+@TABLE_NAME+' WHERE '+@IND_NAME+' = '''+@IND_VALUE+'''')
>   BEGIN TRY
>      EXECUTE (@Stmt);
>   END TRY
>   BEGIN CATCH
>      SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_MESSAGE() AS ErrorMessge;
>   END CATCH
>);
>GO
>
>
>The DECLARE statement seems to be the beginning of the problem, but Im not sure how else to write it. ... All help is appreciated.
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform