Dynamic query


New Member

how can we have a dynamic query for below condition ?.

I have input as list of table's, for example msg_mstr, lbl_mstr, lbld_det etc..
now i will take you through msg_mstr.

x2msg_mstr is shadow table for msg_mstr. it contains primary unique fields of msg_mstr(msg_lang and msg_nbr) and additionally with ticket number field.

for x2msg_mstr table - x2msg_ticket, x2msg_lang and x2msg_nbr is primary unique key.
Single ticket number will have multiple message numbers.

Now my condition is to take dump of msg_mstr table for the input particular ticket.

for each x2msg_mstr where x2msg_ticket = "ticket1" no-lock:
find first msg_mstr where msg_lang = "us" and msg_nbr = x2msg_nbr
no-lock no-error.
if available msg_mstr then
export msg_mstr.
end. /*for each x2msg_mstr*/

similarly for all the tables which is in list i need to create the dump.

your advice will be helpful. Thanks in Advance.
tablename = "msg_mstr".
squery = "for each x2" + tablename + " where x2" + tablename + " = 'ticket1' no-lock,".
squery = squery + "each " + tablename + " where " + "x2" + tablename + ".fieldname = " + tablename + ".fieldname no-lock."