Error executing sqlcmd command through UNIX

Hi All,

I am trying to execute a set of sql statements in sql server 2008 using the sqlcmd command in unix and passing the query in the "input" parameter. It is giving me an error "incorrect syntax near 2014". The below statement is giving an error :

 declare date_val datetime,
 select @date_val = '2014-01-01 23:00:00:999'
 

I have used the same sql in sql server database and it is working fine by but when I am using ''2014-01-01 23:00:00:999'' in sql server directly the it is throwing the same error.

Please suggest how this can be resolved.

Thanks in advance!

Is it expecting 23:00:00:999 or 23:00:00.999 ? Most systems I've seen use a period to separate seconds from milliseconds; not a semicolon.

Hi Don,

It is a typo mistake. The date is @date_val = '2014-01-01 23:00:00.999' only. Thanks for pointing it out.
The same sql is working in sql server but giving error in unix.

Please suggest.

  1. Show us the entire script, not just two lines from the SQL query, and show us the entire, exact diagnostic message (both in CODE tags) that you get when you run that script.
  2. What shell is being used to run your script?
  3. What operating system (including release number) are you using? If you don't know the release, show us the output from the command: uname -a (also in CODE tags).
  4. What operating system is running on the system where your database is running?
  5. What database software are you using?

Without the above basic information, we have a much very limited chance of offering any real help.

I was able to run SQL Server commands from Linux using the following command:
Just substitute your ip address, instance port and username. You can store the
password in the SQLCMDPASSWORD variable. The -e flag echo's input, the -b flag
causes it to abort on error, and the -i flag specifies the input file.

Otherwise it was running proper SQL Server syntax. I did add a GO between each
command. You may need to do the same.

SQLCMDPASSWORD=<pwd>
sqlcmd -U "<username>" -S <server ip address>,<server port> -e -b -i sql_to_run.sql