Hi ,

I am using following Dynamic SQL statement in a stored procedure :

EXECUTE IMMEDIATE ' UPDATE AsterixModel SET CURRENTIDTOKEN = ' || p_currentidtoken || '+ 500
WHERE ModelID = :1' USING p_modelid ;

Here p_modelid is an IN parameter and currentidtoken is an OUT parameter being passed to the procedure.

Now my questions are:

1). Is there any advantage of using dynamic sql over simple sql statement in the above case, I mean if instead of using Execute Immediate , what if I use

UPDATE AsterixModel SET CURRENTIDTOKEN = ' || p_currentidtoken || '+ 500 WHERE ModelID = p_modelid

Would it make any difference including performance.

2) In case I have to use EXECUTE IMMEDIATE, how can I write the same query in DB2 with USING clause. In DB2 , I tried it like this :

SET stmt =' update AsterixModel set currentidtoken = ' || char( P_CURRENTIDTOKEN) || char(tempVar) || 'where ModelID = :1' || USING || char(P_MODELID) ;
EXECUTE IMMEDIATE stmt;

But the USING caluse didn't work. Any idea how to use USING clause here.
3) If I write the same query without using USING clause as mentioned in point (1), would it make any difference.

Thanks & Regards