Jameschowdare
You can't directly call a sp from a function(udf). Only functions and extended stored procedures can be executed from within a function.
But you can use openquery & sp_executesql within the function. Following is an example for that
CREATE function [dbo].[createstring](@sqlstr nvarchar(32), @sql nvarchar(max))
returns nvarchar(max)
with execute as caller
as begin
declare @out_sql nvarchar(max)
return 'select * from openquery('+@sqlstr +', '''+REPLACE(@sql,'''','''''')+''')'
end
declare @a nvarchar(512)
set @a = (select [dbo].[createstring](N'SRV', @query))
exec sp_executesql @a
I hope this is what you are expecting. Mark as answer if it is.
Mark this as answer, if it is.....
With regards
Nishithraj Narayanan
Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator