Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. procedure insert_plan_to_dep_show_char
  2. as
  3. begin
  4. merge
  5. into dep_show_char c
  6. using (
  7. select 20355682000000 as form_id, c.object_id as char_id, c.is_plan
  8. from dep_bonus_char c left join dep_product p on c.product_id = p.object_id
  9. where c.is_plan = cst.true
  10. and c.type_id in ( dep_bonus_char_type_cst.purchase_sum, dep_bonus_char_type_cst.share_in_total, dep_bonus_char_type_cst.urgent_percent, dep_bonus_char_type_cst.any_char)
  11. and c.val_id in ( cst.num, cst.txt )
  12. and c.act_start_date >= to_date('01.01.2016','DD.MM.YYYY') and c.act_end_date < to_date('01.01.2018','DD.MM.YYYY')
  13. ) s
  14. on ( s.form_id = c.form_id
  15. and s.char_id = c.char_id
  16. )
  17. when matched then update set
  18. c.is_plan = s.is_plan
  19.  
  20. when not matched then insert
  21. ( form_id, char_id, is_plan)
  22. values
  23. ( s.form_id, s.char_id, s.is_plan);
  24.  
  25. end;
  26. /
  27.  
  28. procedure insert_fact_to_dep_show_char
  29. as
  30. begin
  31.  
  32. merge
  33. into dep_show_char c
  34. using (
  35. select 20355682010000 as form_id, c.object_id as char_id, c.is_fact, c.product_id
  36. from dep_bonus_char c left join dep_product p on c.product_id = p.object_id
  37. left join dep_uom u on c.uom_id = u.object_id
  38. where c.type_id not in (
  39. dep_bonus_char_type_cst.bonus_percent
  40. , dep_bonus_char_type_cst.mix
  41. , dep_bonus_char_type_cst.group_minus
  42. , dep_bonus_char_type_cst.bonus_sum
  43. , dep_bonus_char_type_cst.share_in_total
  44.  
  45. )
  46. and c.val_id in ( cst.num, cst.fle, cst.txt )
  47. and not (
  48. c.type_id = dep_bonus_char_type_cst.purchase_sum
  49. and c.product_id = dep_product_cst.car
  50. and c.uom_id = dep_uom_cst.rub
  51. ) and c.type_id not in ( dep_bonus_char_type_cst.total_bonus_percent, dep_bonus_char_type_cst.help)
  52. and (c.is_fact = cst.true or c.type_id = dep_bonus_char_type_cst.min_plan)
  53.  
  54. /* and (v_object_type_id = AP_DATA_TYPE_CST.bonus_fact and c.type_id not in (dep_bonus_char_type_cst.indep_char) or
  55. v_object_type_id = AP_DATA_TYPE_CST.other_chars and c.type_id in (dep_bonus_char_type_cst.indep_char))*/
  56. and act_start_date >= to_date('01.01.2016','DD.MM.YYYY') and act_end_date < to_date('01.01.2018','DD.MM.YYYY')
  57.  
  58. ) s
  59. on ( s.form_id = c.form_id
  60. and s.char_id = c.char_id
  61. )
  62. when matched then update set
  63. c.is_fact = s.is_fact
  64.  
  65. when not matched then insert
  66. ( form_id, char_id, is_fact)
  67. values
  68. ( s.form_id, s.char_id, s.is_fact);
  69.  
  70. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement