I have a query script tool which is run in multiple environments, with many in-script references to the database where the script is running. Rather than have to manually edit each of those instances at run-time, I'd like to set a variable at the top of the script so the database value can be assigned once.
I'd declare the variable so:
DECLARE @db VARCHAR(25) = 'some database name'
And then I'd like to use that variable in a reference to a table path, e.g.:
SELECT 1 FROM @db.sys.partitions
Is something like that possible? If so, how could it be constructed? Thanks.