Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Table valued inline function syntax
Message
De
03/02/2014 10:23:13
 
 
À
03/02/2014 10:16:36
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01592983
Message ID:
01592998
Vues:
29
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)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform