I am trying to execute a certain command using sp_executesql function available in MSSQL, but I somehow need to return a 'result' code back to the calling procedure. I understand from MSSQL's help that the commands in sp_executesql are sent to the server as a separate batch, and as such cannot directly reference calling procedure's variables.

I was wondering if there is a way of returning such 'result' code without having to physically write it to some location in the DB (which the calling procedure would then read).

Any help on this would be greatly appreciated.