Hi @nononame2021
what is the function of <:SETVAR ABCDbName "[test123]">
why it need to add $ in sql script?
Simply put, ':SETVAR' and '$' are used to declare variable and use variable in SQLCMD Mode.
The ':SETVAR' only works in SQL command mode, so first of all, you need to enable sqlcmd mode in SQL Server Management Studio. This can be done by going to the "Query" menu, and selecting "SQLCMD mode" .
Then have a test on this code:
:SETVAR DatabaseName "your_database_name"
:SETVAR SchemaName "your_SchemaName"
:SETVAR TableName "your_table_name"
USE $(DatabaseName);
SELECT *
FROM $(SchemaName).$(TableName);
Finally
is [test123] a database name?
You will find the answer to this is Yes
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.