Search code examples
sql-serverlinuxubuntusqlcmd

How to call stored procedure with xml parameters using sqlcmd on Ubuntu


On my Ubuntu machine, I need to call a stored procedure which accepts XML input parameter. I am not getting the correct way to call the stored procedure passing the parameter. I have tried below commands

XML=$(echo "cat doc.xml")
sqlcmd -Q "exec MyStoredProc @Dataxml=$($XML)"

Or

sqlcmd -Q "exec MyStoredProc @Dataxml=$XML"

Or

sqlcmd -Q "exec MyStoredProc @Dataxml=$(XML)"

But none of these really worked. My sqlcmd version is 17.1.0000.1 Linux


Solution

  • Pass the XML parameter value as a string literal:

    sqlcmd -Q "exec MyStoredProc @Dataxml='$XML';"