declare @s varchar(max)
set @s=''
SELECT row_number() over (order by id) as rownumber, text into #er FROM syscomments where id in(
select id from (
SELECT id,count(1) as _count FROM syscomments where encrypted=0 and id in(
SELECT id FROM sysobjects where (type='p' or type='v' or xtype='fn' ) and category=0 and left(name,3)!='sp_' and left(name,3)!='fn_' )
group by id
having count(1) =1
)_a
)
declare @max int
select @max=max(rownumber)
from #er
declare @rowNo int
declare @asbegin int
set @rowNo=1
while @rowNo<=@max
begin
select @s=text from #er where rownumber=@rowNo
set @s=replace(@s,'create','alter')
SELECT @asbegin = PATINDEX ('%[^A-Z,0-9]AS[^A-Z,0-9]%', @s)
SELECT @s = SUBSTRING(@s, 1, @asbegin - 1)+ ' WITH ENCRYPTION AS ' + SUBSTRING (@s, @asbegin+3, LEN(@s))
print @s
exec( @s)
set @rowNo=@rowNo+1
end
drop table #er