Took me a while to get the database and filegroup references worked out and up and running. Not the worst code I've ever seen but very close to it. Commas at the beginning of lines makes my skin crawl. I'd be embarrassed to have my name on this in a corporate setting. Breaking out the table creates might make it easier for newbies. Seems to run quickly in non-execute mode. Later I'll dive into the log tables and actual results to see if any magic is going on.
I've encountered an error for my indexes named 128 characters long. QuoteName returns nvarchar(258) but your table columns are nvarchar(128). I simply removed QuoteName calls since I never use weird names.
Also, I run the process and minutes later it wants to Reorganize a 1000 indexes again. What is going on?
Reorg seems to not work on indexes with less than 300 pages.
Rebuild seems to not work on indexes with less than 32 pages.
I'm just going to force Rebuild all the time and rip out the reorg coding.
The @ver variable check is inconsistent throughout and obviously an error.
The deprecated != is used throughout.
I question the fill factor 80% since that lowers your data cache density. I'd probably run at 95% if reindexing weekly.
After two days of working on this proc, I'm realizing what a hunk of junk it was.
I've found more semantic errors so proc will act unexpectedly.
I seriously question why clustered indexes are not rebuilt before non-clustered ones.