• Shawn Melton (5/5/2015)


    Alan.B (5/5/2015)


    I'm not trying to belittle Shawn's solution as he was just fixing your code.

    It is worth noting, however, that sp_MSForEachDB is undocumented and you should never use undocumented code in production environments. You could use a Dynamic SQL and sys.databases to accomplish the same thing.

    I'm pretty sure the OP is aware of this as he stated: :hehe:

    Please no replies about how sp_MSForeachdb is unreliable.

    Thank you!

    Yep. Duh (smacking own head)

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001