Reputation: 23
We have a stored procedure that uses UDFs. We need to modify the content of these UDFs on the fly. Yeah, I know, I know... Not my choice. This is exactly what we are tying to do:
executesql
statementIs there a way to get the contents of a udf into a varchar (or nvarchar) that I can then modify using string functions?
Upvotes: 2
Views: 184
Reputation: 139000
select object_definition(object_id('UDFName'))
Is there a way to get the contents of a udf into a varchar (or nvarchar) that I can then modify using string functions?
declare @str nvarchar(max)
-- get function definition to @str
select @str = object_definition(object_id('UDFName'))
-- Modify definition
set @str = replace(@str, 'CREATE FUNCTION', 'ALTER FUNCTION')
-- execute alter function
exec (@str)
Upvotes: 3