Maybe this:
$path_to_bin/sqlcmd -U ${user_name} -P ${password} -S ${sqlserver_ip_address} -d ${database_name} -Q "DECLARE @ERROR_CODE int, @ERROR_TEXT nvarchar(2048) EXECUTE PROCESS_STG_DATA '$(v_file_name)' @ERROR_CODE OUT @ERROR_TEXT OUT;" -v v_file_name=${file_name} SELECT @ERROR_CODE, @ERROR_TEXT" P_ERR_TXT=''>>$path_to_log/LOG_FILE.LOG
Some observations:
- You must declare the variables for the output parameters in the SQL batch.
- To refer to the variable defined with the -v option, you use $(). (I hope that the Unix shell does not react on the $.)
- I don't know what there P_ERR_CD and P_ERR_TEXT were supposed to be. They did not make any sense with the T-SQL syntax I deleted.
- Instead I added a SELECT of the two variables. That is the only way you can get back the values from SQLCMD.