Friday, February 10, 2012

calling use @dbname in a cursor

Folks,
I am trying to use a cursor to run space check on each db on the server
OPEN cur_DBs
FETCH NEXT FROM cur_DBs INTO @.DBName
WHILE @.@.FETCH_STATUS = 0
BEGIN
--************************************************** ************************************************** ******************
use @.DBName
won't let me do the "use @.dbname" to switch to the db I want to use.
Any ideas?
Thanks,
MPM
Try:
sp_MSforeachdb 'EXEC [?].dbo.sp_spaceused'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"MANCPOLYMAN" <MANCPOLYMAN@.discussions.microsoft.com> wrote in message
news:8CC1C001-4D22-43C3-A0FF-C32F13EBB2AC@.microsoft.com...
> Folks,
> I am trying to use a cursor to run space check on each db on the server
> OPEN cur_DBs
> FETCH NEXT FROM cur_DBs INTO @.DBName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> --************************************************** ************************************************** ******************
> use @.DBName
> won't let me do the "use @.dbname" to switch to the db I want to use.
> Any ideas?
> Thanks,
> MPM
|||Tibor,
I behold the beauty of the internet. Exactly what I am looking for.
Thanks a lot,
Brian
"Tibor Karaszi" wrote:

> Try:
> sp_MSforeachdb 'EXEC [?].dbo.sp_spaceused'
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "MANCPOLYMAN" <MANCPOLYMAN@.discussions.microsoft.com> wrote in message
> news:8CC1C001-4D22-43C3-A0FF-C32F13EBB2AC@.microsoft.com...
>
>

No comments:

Post a Comment