• I had a problem with the script generating the drop statements for my clustered and nonclustered indexs that are not Primary Keys.

    The following statement would not return the object id and therefore would use the previous indexes information when it did the print statement for @sdropsql

    so.object_id = object_id ( @idxTableName) and si.index_id = @idxid and si.type IN ( 1,2) -- is_primary_key = 0

    I changed the @idxTableName to the actual object id, @idxTableID and it worked. Upon further investigation If I added the schema name in front of the @idxTableName it would also work correctly.