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