Progess / Project 702 / Project Challenges

T-SQL Command Line Arguments

I am currently working on automating the climate chip analysis process. It is a mix-and-match of Python code for the calculations and callable command line scripts to manage the database. To be truly effective, I have had taken advantage of T-SQL’s ability to accept command line arguments (called “scripting variables”(1) by Microsoft). In general you can pass arguments to T-SQL scripts using the following syntax:

USE climate30Year;
GO

SELECT latitude, longitude, month, Tmax
  FROM cru30Year
  WHERE year=$(PARAM);
GO

and then, from the terminal use sqlcmd and the -v switch:

#> sqlcmd -v PARAM ="<value>" -i <scriptName> -S <serverInstance>

References:
(1) http://msdn.microsoft.com/en-us/library/ms188714.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s