From: Erland Sommarskog on
nzrdb6 (alex.campbell(a)sqltechconsulting.co.uk) writes:
> I'm struggling to get this script to run on all DBs. It runs on a
> single DB just fine. Tried sp_msforeachdb but can't get the syntax
> quite right when using it in conjunction with @sql. Any ideas please.

I see that you already have a solution, but I think easiest way would
be to just run a cursor over sys.databases.

--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx