• You can't use ms_foreachdb to insert a parameter into a query that's directly executed. You need to submit a query as a parameter.

    Luis has shown you how this would work.