Lovely script but one (minor) problem caused a few headaches. If the database name needs to be bracketed e.g. [2005] then it fails.
The line
FROM " + @dbname +".INFORMATION_SCHEMA.COLUMNS
needs to read
-
FROM [" + @dbname +"].INFORMATION_SCHEMA.COLUMNS
-
to cope with this.