Search code examples
sybasesap-ase

How to use RETURN_VALUE parameter in 'Create proc as EXEC' in Sybase?


I'm trying to prepare stored procedure with TDS_DYN_PREPARE like

'create proc dyn1 as EXEC @RETURN_VALUE = sel_from_emp'

If I trying to use statement as is error 'Must declare variable '@RETURN_VALUE'
If parameter name replaced with ? (required for input params, but I tried on return value too) error 'The untyped variable ? is allowed only in in a WHERE clause or the SET clause of an UPDATE statement or the VALUES list of an INSERT statement'

Is it possible to use return value in such statement and if yes - how?


Solution

  • What you're doing here is executing a proc named sel_from_emp which apparently returns a status value (ASE procs can do that). Is this what ypu expected? This status value is captured in variable @RETURN_VALUE -- but that variable is not declared, so you must add a statement DECLARE @RETURN_VALUE INT. Note that capturing the proc return statis mskes sense pmly when you sre going to do domething with that value, otherwise you can you do EXEC sel_from_emp.