database - how to Set variable in INFORMIX DB according to IF else condtion for a dynamic SQL -


    create procedure table_info (parin char(12), parin2 char(12), parin3 char(20),parin4 char(2)) returning char(12) paramenter1,char(23) parameter2,char(2) parameter3,char(12) parameter4,char(1) parameter5,integer parameter6 ; define paramenter1 char(12); define parameter2 char(22); define parameter3 char(2); define parameter4 char(12); define parameter5 char(1); define parameter6 integer; define cust_qry   char(1024); let cust_qry = "select pt.paramenter1,pt.parameter2,pt.parameter3,pt.parameter4,pt.parameter5,pt.parameter6              x pt, outer x ps   pt.set_no = ps.set_no ,   pt.paramenter1 = '" || parin || "' ";  if    parin2 = '' let cust_qry = cust_qry ; else let cust_qry = cust_qry || "and pt.parameter4 = '"|| parin2 || "' " ; end if; if parin3 != ''  let cust_qry = cust_qry ||"and pt.trd_blk_ref = '"|| parin3 ||"' " ;     end if; if ( parin4 != '0')  let cust_qry = cust_qry ||"and pt.parameter3 = '"|| parin4 ||  "' " ; end if;         prepare stmt_id cust_qry;    declare cust_cur cursor stmt_id;    open cust_cur;       while (1 = 1)      fetch cust_cur paramenter1, parameter2,parameter3,parameter4,parameter5,parameter6;      if (sqlcode = 100 ) exit; end if;       return paramenter1,parameter2,parameter3,parameter4,parameter5,parameter6 resume ;         end while; 

i have cerated store procedur in informix db .it has created without error . , excutes without anyerror . problem is not recongnizing if else condition have added let cust_qry = cust_qry || "and pt.parameter4 = '"|| parin2 || "' " ;

please me :(

i have no problem in compiling , excuting store procedure if pass parameter 1 , parameter 2 store procedure not going if condition have mentioned if parin2 != '' let cust_qry = cust_qry || "and pt.parameter4 = '"|| parin2 || "' " ;

so query should dynamix , resulted query should below have passes both parin /parin2

select pt.paramenter1,pt.parameter2,pt.parameter3,pt.parameter4,pt.parameter5,pt.parameter6 x pt, outer x ps pt.set_no = ps.set_no , pt.paramenter1 = '" || parin || "' , pt.parameter4 = '"|| parin2 || "'" ;

but problem giving me query till

select pt.paramenter1,pt.parameter2,pt.parameter3,pt.parameter4,pt.parameter5,pt.parameter6 x pt, outer x ps pt.set_no = ps.set_no , pt.paramenter1 = '" || parin || "'

its not considering parin2 when not null .. please help

you add following 2 lines after define in debugging procedure.

set debug file '/tmp/trace.log'; trace on

please post trace.log


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -