I am preparing a group of sql queries for a dashboard. I want to declare the database name at the beginning so that the queries will work on the database specified on top without making any changes in the underlying code
Original query:
SELECT * FROM Check.dbo.Dates_table The query I want:
DECLARE @Databasename VARCHAR(200) SET @Databasename = 'Check.dbo' SELECT * FROM @Databasename.Dates_table
USE [somedb]command? Why try to pass it as a parameter? In any case, the database isn't a value so it can't be treated as a parameter.