Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Stored Procedure call

Status
Not open for further replies.

ejazkhan

Programmer
Jun 21, 2001
3
GB
I am calling some SP's inside a parent SP, but the call for child SP's is dynamic.
I select the name and the variables from a table for the call, join them together in a variable called STATEMENT, which is like this
(proc_glove_1 @supp_code, @work_code, @r_code output, @reason output, @result output with recompile),
and then put that variable in a sp call.
EXECUTE (@statement)
But for some reason sybase server returns an error
Error: Incorrect syntax near '@supp_code'., Batch 1 Line 1
(supp_code is the first variable in the call)
Now if i copy the same call at the same place and try to run like this, (
EXECUTE sp_ proc_auth_glove_1 @supp_code, @work_code, @r_code output, @reason output, @result output with recompile), it works.
Now is there any way that i can do this using that first call i-e Dynamically.

Thanx
 
Looks like you can't join the procedure name and the variables in the one string. I can't find anything in the manuals stating this - but I know below should work:

Code:
select @statement = "proc_glove_1"
select @a = {your first variable value}, @b = {your 2nd variable value}

Exec @statement @a, @b
 
I have already tried your solution but for some reason it does not work too. i found the solution by passing all the variables in a temp table instead of passing them in the string and then selecting these in child proc from that temp table. As if you call just the proc name (without variables) the dynamic statment works. [[ EXEC (@string) ]]This way i do not need to pass the vars in the EXEC call.
Anyway thanx for you time and reply.

Cheers
 
Why do you want to do that.

Is there a reason.

You can as well, do all the tasks needed by passing
multi variables to the SP from anywhere.

So why, do you want to complicate ??
 
Hi Frankenstein
Could you please explain what you are suggesting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top