Skip to Content

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

Now in query editor type following SQL.


: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.



Marcelo Silva Santos

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply