Posted by Erland Sommarskog on 02/08/07 22:39
SQLJunkie (vsinha73@gmail.com) writes:
> Thanks everyone for the replies. The following example is fine for
> generic SPs:
> SELECT @SPname = @DatabaseName + '.dbo.SPName'
> EXEC @SPname
>
> But what if I have to run SPs like SP_updatestats etc? then it will
> not work.
Au contraire, it will work just fine! If you say:
EXEC mydb..sp_systemprocedure
the system procedure will execute in the context of mydb.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|