SELECT pro.sfapro, pro.sigdep, pro.codpro, prm.nompro, pro.codblocage, decode(sign(dsk.c01 - dsk.c02 - dsk.c03), -1, 0, dsk.c01 - dsk.c02 - dsk.c03) dispo, (dsk.c01 - dsk.c02 - dsk.c03 + dsk.c05 + dsk.c04) terme, round(tsc.prxtar, 2) prxtar, tsc.coddev, tsc.datfin, des.lib1 destination, pro.codzn3 dest, pro.motcle, max(nvl(n.numnew, 0)) numnew FROM wt_news n, wv_prm prm, tbl des, mev mevdes, tsc, mev mevtsc, dsk, mev mevdsk, parav, mev mevparav, pro, mev mevpro, fam, mev mevfam WHERE mevfam.codent = 'FAM' and mevfam.segment = 'PRO' and fam.codsoc = mevfam.codsoc_phy and fam.typtie = 'PRO' and mevpro.codsoc = mevfam.codsoc and mevpro.codent = 'PRO' and mevpro.segment = ' ' AND pro.codsoc = fam.codsoc and pro.fampro = fam.codefam AND pro.sfapro = fam.codesfa AND pro.ssfpro = fam.codessf and pro.codpro not like 'SAV%' and pro.suistk = 'S' and pro.codblocage not in ('ECH', 'INT') and ((pro.sigfou = ? and fam.codefam = 'BOU' and fam.codessf in (' ', 'SANS')) or (pro.ssfpro = fam.codessf)) and mevdsk.codsoc = pro.codsoc and mevdsk.codent = 'DSK' and mevdsk.segment = ' ' and dsk.codsoc = mevdsk.codsoc_phy and dsk.codpro = pro.codpro and dsk.sigdep = pro.sigdep and (pro.codblocage not in ('STO', 'SOM', 'FDS', 'NAP', 'SOL') or (pro.codblocage in ('STO', 'SOM', 'FDS', 'NAP', 'SOL') and (dsk.c01 > 0 or dsk.c02 > 0 or dsk.c03 > 0 or dsk.c04 > 0 or dsk.c05 > 0))) and exists (select null from tie dep, mev mevdep where mevdep.codsoc = dsk.codsoc and mevdep.codent = 'TIE' and mevdep.segment = 'DEP' and dep.codsoc = mevdep.codsoc and dep.typtie = 'DEP' and dep.sigtie = dsk.sigdep and dep.codzn1 = 'O' and dep.codett = 'ACT') and mevparav.codsoc = pro.codsoc and mevparav.codent = 'PARAV' and mevparav.segment = ' ' and parav.codsoc = mevparav.codsoc_phy and parav.codpar = 'DEVNAT' and mevtsc.codsoc = pro.codsoc and mevtsc.codent = 'TSC' and mevtsc.segment = 'V' and tsc.codsoc = mevtsc.codsoc_phy and tsc.achvte = 'V' and tsc.codpro = pro.codpro and tsc.datdeb = (select max(tsc2.datdeb) from tsc tsc2 where tsc2.codsoc = mevtsc.codsoc_phy and tsc2.achvte = tsc.achvte and tsc2.codpro = tsc.codpro and tsc2.coddev = tsc.coddev and tsc2.datdeb <= to_char(sysdate, 'YYYYMMDD') and decode(tsc2.datfin, ' ', to_char(sysdate, 'YYYYMMDD'), tsc2.datfin) >= to_char(sysdate, 'YYYYMMDD')) and decode(tsc.datfin, ' ', to_char(sysdate, 'YYYYMMDD'), tsc.datfin) >= to_char(sysdate, 'YYYYMMDD') and tsc.coddev = parav.para1 and mevdes.codsoc = pro.codsoc and mevdes.codent = 'TBL' and mevdes.segment = '101' and des.codsoc = mevdes.codsoc_phy and des.codtbl = '101' and des.cletbl = pro.codzn3 and prm.codsoc = pro.codsoc and prm.codpro = pro.codpro and n.codsoc(+) = pro.codsoc and n.codpro(+) like '%' || pro.codpro || '%' and to_char(sysdate, 'YYYYMMDD') between decode(rtrim(n.datdeb), null, to_char(sysdate, 'YYYYMMDD'), n.datdeb) and decode(rtrim(n.datfin), null, to_char(sysdate, 'YYYYMMDD'), n.datfin) and mevfam.codsoc = ? and fam.codesfa = ? and (fam.codessf = ? or (? = 'SANS' and fam.codessf = ' ')) and prm.codlan = ? and (n.typdes = ? or rtrim(n.typdes) is null) and ((null is not null [or pro.codpro = upper(?)] [or pro.refpro = upper(?)] [or fam.codessf = upper(?)] [or prm.nompro like concat('%', concat(upper(?), '%'))] [or prm.tradesig1 like concat('%', concat(upper(?), '%'))] [or prm.tradesig2 like concat('%', concat(upper(?), '%'))] [or prm.tradesig3 like concat('%', concat(upper(?), '%'))] [or fam.libfam like concat('%', concat(upper(?), '%'))]) [or ? = 'Y']) group by pro.sfapro, pro.sigdep, pro.codpro, prm.nompro, pro.codblocage, decode(sign(dsk.c01 - dsk.c02 - dsk.c03), -1, 0, dsk.c01 - dsk.c02 - dsk.c03), dsk.c01 - dsk.c02 - dsk.c03 + dsk.c05 + dsk.c04, tsc.prxtar, tsc.coddev, tsc.datfin, des.lib1, pro.codzn3, pro.motcle |