Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Table valued inline function syntax
Message
From
03/02/2014 10:23:13
 
 
To
03/02/2014 10:16:36
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01592983
Message ID:
01592998
Views:
27
This is REALLY going out of the way, but theoretically you could have a script that actually generates the entire TVF (table valued function) on the fly, based on what column and table names you want to use. The TVF itself would be static. Of course, that means the execution context would need to have the necessary rights to be able to create a TVF on the fly.

For example, this would build a new function on the fly....again, it's really going out of the way.
declare @syntaxsql nvarchar(4000)

set @syntaxsql = N' create function dbo.MyTestFunction ( @VendorID  int) '
set @syntaxsql = @syntaxsql + ' returns table  as return (select * from Purchasing.Vendor where BusinessEntityID = cast(@VendorID as varchar(10))'
set @syntaxsql = @syntaxsql + ' )  '

select @syntaxsql
exec sp_executesql @syntaxsql
After it's created, I could call it....

select * from dbo.MyTestFunction (1676)
Previous
Reply
Map
View

Click here to load this message in the networking platform