Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using variables in SQLCMD for Linux

I'm running the Microsoft SQLCMD tool for Linux (CTP 11.0.1720.0) on a Linux box (Red Hat Enterprise Server 5.3 tikanga) with Korn shell. The tool is properly configured, and works in all cases except when using scripting variables.

I have an SQL script, that looks like this.

SELECT COLUMN1 FROM TABLE WHERE COLUMN2 = '$(param1)';

And I'm running the sqlcmd command like this.

sqlcmd -S server -d database -U user -P pass -i input.sql -v param1="DUMMYVALUE"

When I execute the above command, I get the following error.

Sqlcmd: 'param1=DUMMYVALUE': Invalid argument. Enter '-?' for help.

Help lists the below syntax.

[-v var = "value"...]

Am I missing something here?

like image 752
GPX Avatar asked Jul 26 '12 11:07

GPX


1 Answers

You don't need to pass variables to sqlcmd. It auto picks from your shell variables: e.g.

export param1=DUMMYVALUE

sqlcmd -S $host -U $user -P $pwd -d $db -i input.sql

like image 135
Anand Avatar answered Oct 12 '22 11:10

Anand