You are here:   Home
Register   |  Login

Programmer Newsletter

Minimize

Master Programmer

Minimize

Find articles on computer software, programming, ASP.net, Sql server, databases, C#, websites, Internet, Windows, Outlook macros.

Programming Articles

Minimize
22

Sqlcmd utility reference with description of setvar is here.
http://msdn.microsoft.com/en-us/library/ms162773.aspx

There is a good article on variables in sqlcmd using setvar.
http://blogs.msdn.com/gertd/archive/2007/01/08/variables-to-the-rescue.aspx

In Sql Server Management Studio, script filenames end with .sql. For sqlcmd scripts, I use .sqlcmd.sql to distinguish from a transact only .sql script.
www.programmer.bz/Forum/tabid/259/forumid/8/postid/47/scope/posts/Default.aspx

Unfortunately, you cannot use sqlcmd script variables within the :setvar statement. So you cannot do something like this.

:setvar pathscripts "c:\sql\scripts\"
:setvar pathmyscripts $(pathscripts)"my\"

You can use sqlcmd script variables in other sqlcmd and transact sql statements.

In sqlcmd statements you do not quote the variables.

:setvar pathscripts "c:/sql/scripts/"
:r "$(pathscripts)"myscript.sqlcmd.sql

In transact sql statements you must quote the sqlcmd variables, otherwise you get errors from transact sql.

print 'pathscripts=$(pathscripts)'

Posted in: Sql

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Name (required)

Email (required)

Website

Programmer Newsletter

Minimize

Subscribe to the Internet Handholding newsletter

MAKE YOUR PC SUPER FAST Discover 5 Shockingly Simple Techniques That Will Make Any Old Computer Run At Top Speed.

Drive Traffic to Your Website with Article Underground. Increase Your Visitors and Your Profits.

HOW TO HYPNOTIZE ANYONE AT WILL! Amazing Secrets to Hypnotize Anyone, Anywhere, at Any Time for Whatever Reason.



Programming Bookmark

Minimize

Share/Bookmark Bookmark and Share