I've got this t-sql snippet:
DECLARE @db_name varchar(255);
SET @db_name = 'MY_DATABASE'; -- assuming there is database called 'my_database'
USE @db_name -- this line ends with error "Incorrect syntax near '@db'."
But USE with variable (third line of snippet) doesn't work. Why it doesn't work?
You cannot provide the name of the database for USE
statement in a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With