Page 1 of 1

Changing where criteria in the program

PostPosted: Thu Feb 16, 2012 8:25 pm
by vegafacundodaniel
Hello,

I have a question pls.

In a cobol/db2 program, can I modify the WHERE criteria of a query sql ?

for ex:
cond1 = "where nroemp = 'XXXXXXX'
cond2 = "where nro emp ='XXXXXXX' and country = 'USA' "

Select nroemp
into ws-nroemp
from base.tb
where cond1

Select nroemp
into ws-nroemp
from base.tb
where cond2

For both querys I am getting the same colonne (nroemp)

Thanks in advance !

Re: Changing where criteria in the program

PostPosted: Fri Feb 17, 2012 2:35 pm
by Nik22Dec
Yes, you can. Please note that after making the change you will have to recompile as well as rebind the program.

It is absolutely possible for both your queries to return the same rows. Why do you think it is an issue?

Re: Changing where criteria in the program

PostPosted: Fri Feb 17, 2012 3:22 pm
by Anuj Dhawan
Short answer is - it can be done, as Nik also indicates. However, rather interesting question is to know why are you asking? If you don't trust the results of your queries, may be browse through the tables uisng SPUFI and QMF and see what is there in your table/s?

Re: Changing where criteria in the program

PostPosted: Sun Mar 08, 2015 3:50 am
by vegafacundodaniel
Hello. In my program cobol/db2, I am using theses sentences:

01 cond1 pic x(30).

move "nroemp = 'XXXXXXX'" to cond1

EXEC SQL
Select nroemp
into ws-nroemp
from base.tb
where cond1
END-EXEC.

and when I compile, I get an error on the WHERE.
Could anyone help me, please?

thanks in advance

Re: Changing where criteria in the program

PostPosted: Sun Mar 08, 2015 4:09 am
by vegafacundodaniel
vegafacundodaniel wrote:Hello. In my program cobol/db2, I am using theses sentences:

01 cond1 pic x(30).
01 var-employe pic 9(8).

move "nroemp1 = :var-employe'" to cond1
move 11111111 to var-employe

EXEC SQL
Select nroemp
into ws-nroemp
from table
where cond1
AND nroemp2 = 99999999
END-EXEC.

and when I compile, I get an error on the WHERE.
Could anyone help me, please?

thanks in advance

Re: Changing where criteria in the program

PostPosted: Sun Mar 08, 2015 4:41 am
by BillyBoyo
Please don't ask a new question in an old topic.

What were you hoping "where cond1" would do?