>so - how can I "use" a database that is passed in as a parameter or determined somehow and stored in a variable - short of putting everything in one big variable and executing it?
>
>specifically (in pseudo code) I want to:
>
>1 - save current database (which can be anything) in variable
>2 - switch to another known database
>3 - do some stuff
>4 - switch back to orignal database
Unfortunatly, I have no idea on that. However, maybe this can work in your case: in number 3 (do some stuff), if you are building your queries on the fly, you could use the full declarative of the tables you are using, which is database.owner.name . For example, this will work (tested):
use master
select * from pubs.dbo.authors
I don't know if this applies to your situation, though...
Sylvain Demers