0

I am trying to convert OSQL comamnd to SQLCMD as below. The OSQL command is working fine,but converted SQLCMD is throwing below error, Please help.

Original OSQL:

osql.exe -S TestDB -E -d TestDB -Q EXIT("Declare @ExecutionResult int  EXEC dbo.p_SP @ExecutionId='test', @ExecutionResult=@ExecutionResult OUTPUT select @ExecutionResult") 2>&1

Converted SQLCMD:

sqlcmd -S tcp:TestDB -E -d TestDB -Q EXIT("Declare @ExecutionResult int  EXEC dbo.p_SP @ExecutionId='test', @ExecutionResult=@ExecutionResult OUTPUT select @ExecutionResult") 2>&1

SQLCMD Error: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Sqlcmd: 'Declar... '-?' for help.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError

Pradeep H
  • 592
  • 2
  • 7
  • 27
  • Probably not your problem, but it would help if you put semi-colons after each statement in your multi-statement SQL String, so it's easier to read/parse/understand. – pmbAustin Dec 10 '18 at 17:29
  • 1
    Don't think you need to specify EXIT and also add some semicolons sqlcmd -S tcp:TestDB -E -d TestDB -Q "Declare @ExecutionResult int; EXEC dbo.p_SP @ExecutionId='test', @ExecutionResult=@ExecutionResult OUTPUT; select @ExecutionResult;" 2>&1 – Daniel N Dec 10 '18 at 17:30
  • @DanielN Thank you. This resolved the problem I was facing. – Pradeep H Dec 10 '18 at 18:34

1 Answers1

0

Check SQLS**Plus on https://www.sqlsplus.com. It can do much better formatting - loke Oracle' SQL*Plus but for SQL Server.

Ron Warshawsky
  • 314
  • 2
  • 11