REbuilding indexes is done with ALTER INDEX ... REBUILD. That's all that's needed.
Was the long query not to identify which indexes needed rebuilding perhaps?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability