Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. begin
  2. merge into {bitlog_schema}.sorderlines sol
  3. using
  4. (
  5. select
  6. gtt.soid, gtt.ln, gtt.artid, gtt.qty, gtt.prc, gtt.curency, gtt.cartons, gtt.type, gtt.vat, gtt.year_reserve, gtt.number_reserve,pcb
  7. from {bitlog_schema}.{gtt_solines_table} gtt
  8. ) gtt
  9. on (sol.soid = gtt.soid and sol.ln = gtt.ln and sol.artid = gtt.artid and sol.pcb = gtt.pcb)
  10. when matched then
  11. update set
  12. sol.qty = gtt.qty,
  13. sol.curency = gtt.curency,
  14. sol.cartons = gtt.cartons,
  15. sol.type = gtt.type,
  16. sol.vat = gtt.vat,
  17. sol.year_reserve = gtt.year_reserve,
  18. sol.number_reserve = gtt.number_reserve,
  19. sol.prc = gtt.prc
  20. where
  21. (
  22. (sol.qty != gtt.qty) or
  23. (sol.curency != gtt.curency) or
  24. (sol.cartons != gtt.cartons) or
  25. (sol.type != gtt.type) or
  26. (sol.vat != gtt.vat) or
  27. (sol.year_reserve != gtt.year_reserve) or
  28. (sol.number_reserve != gtt.number_reserve) or
  29. (sol.prc != gtt.prc)
  30. )
  31. when not matched then
  32. insert (sol.soid, sol.ln, sol.artid, sol.qty, sol.prc, sol.curency, sol.cartons, sol.type, sol.vat, sol.year_reserve, sol.number_reserve,sol.pcb)
  33. values (gtt.soid, gtt.ln, gtt.artid, gtt.qty, gtt.prc, gtt.curency, gtt.cartons, gtt.type, gtt.vat, gtt.year_reserve, gtt.number_reserve,gtt.pcb);
  34. commit;
  35.  
  36. delete
  37. from {bitlog_schema}.sorderlines sol
  38. where
  39. not exists
  40. (select 1
  41. from
  42. {bitlog_schema}.{gtt_solines_table} gtt
  43. where
  44. sol.soid = gtt.soid
  45. and sol.ln = gtt.ln
  46. and sol.artid = gtt.artid)
  47. and sol.soid in (select gtt.soid from {bitlog_schema}.{gtt_solines_table} gtt group by gtt.soid);
  48. commit;
  49. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement