Skip to content
Advertisement

Return value from dynamic linked server stored procedure

I want to return a value from a dynamic linked server stored procedure.

On the local server, how can I retrieve the value of @DocNumOut? I have trial many combination using EXEC, openquery, EXEC sp_executesql, but none can return the value into my local variable, @DocNumberOUT.

Advertisement

Answer

Use OUTPUT parameter on your Stored Procedure and don’t use the return value.

Use the proper data type. Don’t use varchar for everything. Since you assigned an integer to the variable, declare it as integer.

On the calling side, the error message is telling you that @SQLCMD should declare as NVARCHAR. Using sp_executesql is the right choice. But you should also define the parameters and pass in the variable also. @DocNumOut is the name of the parameter that you defined in SPTEST. @DocNumberOUT is your local variable

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement