Good Script.
Two things:
1. Why do you need to keep the script in the temp table, and not execute it right away?
2. A databases with a spaces in a name would fail this script. Therefore modyfied the following line as:
SELECT 'ALTER AUTHORIZATION ON DATABASE::[' + name + '] TO sa'
Thanks.
Alex Donskoy
SQL Server DBA
Greeneberg Trauriq PA Miami FL