Search code examples
stored-proceduresparameterssql-server-expresssqlcmd

SQLCMD failure executing stored procedure with parameter


New to using SQLCMD.

If I run the following sqlcmd I get an error

Incorrect syntax near '.209

Command:

sqlcmd -E -S MyServer\SQLEXPRESS -d MyDatebase-Q "EXEC spRunThisPS @IP=$(IP)" /v IP="192.168.209.4"

If I just have "192.168" as the parameter the script will run (obviously the PS fails because invalid ip). Not sure if the amount of "." causes it to fail or not.

Any thoughts or suggestions?

Nick


Solution

  • You probably need to wrap the parameter value in quotes, either by specifying the IP value as IP="'192.168.209.4'", or by adding them around the parameter value in the EXEC command (EXEC spRunThisPS @IP='$(IP)').

    Otherwise it's trying to interpret it as a numeric value rather than a string, which is why 192.168 is ok and 192.168.209.4 isn't.