Hello,
We have a number of SQL 7.0 databases where we want to perform the same task on each one, so we have written a stored procedure to perform the task.
The stored procedure uses a USE command to point it at the appropriate database (defaulting to master), which it obtains from a cursor which extracts the database names from sysdatabases, however when the db name is placed into a variable and then the variable passed to the USE command it doesnt work.
i.e USE @DB_Name doesnt do anything.
If the EXEC method 'EXEC ("USE " + @DB_Name)' function is used it works ok but once the EXEC has completed the Db returns to the default db and any subsequent refrences to DB_Name use Master...
Has anybody any suggestions as to how we may achieve this sort of routine or where we may be going wrong?
Thanks.
We have a number of SQL 7.0 databases where we want to perform the same task on each one, so we have written a stored procedure to perform the task.
The stored procedure uses a USE command to point it at the appropriate database (defaulting to master), which it obtains from a cursor which extracts the database names from sysdatabases, however when the db name is placed into a variable and then the variable passed to the USE command it doesnt work.
i.e USE @DB_Name doesnt do anything.
If the EXEC method 'EXEC ("USE " + @DB_Name)' function is used it works ok but once the EXEC has completed the Db returns to the default db and any subsequent refrences to DB_Name use Master...
Has anybody any suggestions as to how we may achieve this sort of routine or where we may be going wrong?
Thanks.