Execute dynamic sql in funtion

Hello friends ,

this is probably one my post which took me so long to varify but negligible time to write it .

We cannot execute dynamic sql in a user defined funtion.

SET @query  = ‘select * from nytable’

exec (@query)  —   this will not work 

neither you can call any stored procedure from a function(except extended stored procedures).

the another possible workaround for this is that you create a stored procedure rather than a UDF or create an extended stored procedure . than you can call it as

exec sp_executesql myextendedSP

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s