SET NOCOUNT ON;
DECLARE @db_name nvarchar(130);
DECLARE @cnt int = 1;
DECLARE @db_cnt int = 0;
DECLARE @dbname nvarchar(130);
DECLARE @dbcmd nvarchar(200);
DECLARE databases CURSOR FOR SELECT name FROM sys.databases
SET @db_cnt = (SELECT COUNT(name) FROM sys.databases)
OPEN databases;
WHILE @cnt < CAST(@db_cnt AS int) BEGIN
FETCH NEXT FROM databases INTO @db_name;
SET @cnt = @cnt + 1;
PRINT N'Using database: ' + @db_name;
SET @dbcmd = N'USE ' + CAST(@db_name AS nvarchar(130));
PRINT @dbcmd;
END;
CLOSE databases;
DEALLOCATE databases;
GO
Hello
Your mileage will vary with that one. What I suggest you try is executing the entire thing as a block.
There is an option on right-click that allows you to execute as a single statement. That's your best bet.
Try that and let me know how you go.
Thanks
Takis
--
You received this message because you are subscribed to the Google Groups "Execute Query" group.
To unsubscribe from this group and stop receiving emails from it, send an email to executequery...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.