I have a script that does a find and replace on other scripts. I get the text of the script using "selece definition from sys.sql_modules..." and store it in a varchar(max) variable. Then I split the text into 3 other variables because "Print" only works on 8000 characters even if the variable is varchar(max). The procedure that I'm doing teh find/replace has almost 22,000 characters, but it seems the varchar(max) only holds 17,245 characters. I've tried
Set @SQL = substring(select definition..., 17246, 8000) but that returns null.
I've also tried
declare @t table(line varchar(8000))
insert @t exec sp_helptext 'sputilCopyEntity'
select * From @T
but it has the same size limitation. The last row is the same as the last of the text when I use the varchar(max) variable.
How can I get the rest of the script?