Link to home
Start Free TrialLog in
Avatar of tallison122065
tallison122065

asked on

Use a variable for the database name?

I am trying to pull the same result set from databases on mulitiple linked servers.  The databases are the same on each, so the same query will work.  I shouldn't have to duplicate this code, I know, but I how do I step through the different dbs?  I can get the db names into a cursor, but "USE @variable" doesn't seem to be allowed.  Also, a full name doesn't work with the "USE" command (USE server.db).

Can someone help me with the best approach to only write my query once?
ASKER CERTIFIED SOLUTION
Avatar of rafrancisco
rafrancisco

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial