IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 stored procedure - error in dynamic sql


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Mon Jun 08, 2009 2:04 pm
Reply with quote

I'm facing a strange problem is db2 stored procedure. A dynamic query is written in the SP and it throws sqlcode -206 at runtime. The query has 6 conditions in where clause and the error throws in one of the condition. When the value is hard coded instead of getting from i/p parameter then the SP executes correctly.
Example: IF v_first_value = 'N' THEN
SET v_query = v_query || ' AND A.ST_AD = ' || in_st_ad;
ELSE
SET v_first_value = 'N';
SET v_query = v_query || ' WHERE A.ST_AD = ' || in_st_ad;
END IF;
The query fails in this condition at run time. If i change
A.ST_AD = ' || in_st_ad to A.ST_AD = ''CA''' then it executes correctly.

Also when the query is changed to static, then the SP executes successfully even if the value for the column is got from i/p
parameter.
Is there any solution for this problem?
Back to top
View user's profile Send private message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Mon Jun 08, 2009 4:02 pm
Reply with quote

Missed quotes in dynamic sql and its working now... Thanks for those who looked into this.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Mon Jun 08, 2009 4:11 pm
Reply with quote

Glad to hear that it's working now and thanks for the follow-up ... icon_smile.gif
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts U0016 error in JCL JCL & VSAM 4
No new posts Any way to prevent dynamic allocation? DFSORT/ICETOOL 6
No new posts python on z/OS error no encoding decl... Testing & Performance 0
No new posts IEW2315E 1369 Link error All Other Mainframe Topics 3
No new posts Excuting store procedure via JCL batch JCL & VSAM 1
Search our Forums:


Back to Top