• Thanks for taking the time and effort to share this code. Very useful. I did run into one problem though. I received this error but ONLY on a single database: Msg 2812, Level 16, State 62, Line 2 Could not find stored procedure 'sp_executeSQL'.

    The problem was that the one database has a case-sensitive collation. I changed 'sp_executeSQL' to 'sp_executesql' and everything was fine.

    Thanks again.

    Lee