Hi

I'm writing a SQL script that reads a table into a cursor and then imports
the data into various tables in another database. I don't know the name
of the source database, so I want to declare the database name as a local
variable. This will allow the end user (the DBA running the script) to put
the database name in when they need to run it. I tried the following:

declare @DBName varchar(40)
set @DBName = 'TestDB'
declare DB_cursor cursor for
select * from @DBName.dbo.ImportData
open DB_cursor

I've found that you can't use a local variable in the database location for
a select statement. Is there some way of achieving the result I'm after?

Thanks.