Enable sqlcmd mode in SQL Server Management Studio as described in following image.

Now in query editor type following SQL.
:SETVAR DatabaseName "SBOPRODIR"
:SETVAR SchemaName "dbo"
:SETVAR TableName "OITM"
USE $(DatabaseName);
SELECT * FROM $(SchemaName).$(TableName);
Note that I have set the value of the database, schema and table as a sqlcmd variable and I am executing the query using the same parameters.

SQLCMD is a relatively simple language to master and it also aids in doing various tasks easily.
References:
http://msdn.microsoft.com/en-us/library/ms188714.aspx
Regards,
Marcelo Silva Santos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 14 | |
| 12 | |
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |