Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. create function arballon.com_creutlmda (@i_cod_emp smallint, @i_cod_amb smallint, @i_tip_opr smallint, @i_cod_opr char(16), @i_cod_dis char(1), @i_fch_cot datetime) returns decimal(18,2) as
  2. begin
  3. declare @s_cre_utl decimal(18,2)
  4. declare @s_dif decimal(18,2)
  5.  
  6. set @s_cre_utl = 0
  7. set @s_dif = 0
  8. set @s_cre_utl = (
  9. select
  10. sum(b.dal_ope)
  11. from anlsdo b
  12. inner join anlcod a on
  13. a.cod_emp = b.cod_emp and
  14. a.cod_amb = b.cod_amb and
  15. a.cod_anl = b.cod_anl and
  16. (@i_cod_dis = ' '
  17. or a.flg_anl = @i_cod_dis)
  18. inner join concta n on
  19. n.cod_emp = a.cod_emp and
  20. n.cod_amb = a.cod_amb and
  21. n.cod_cta = a.cod_cta and
  22. n.tip_res != 'S'
  23. where 1 = 1
  24. and b.cod_emp = @i_cod_emp
  25. and b.cod_amb = @i_cod_amb
  26. and b.tip_opr = @i_tip_opr
  27. and b.cta_anl = @i_cod_opr
  28. and b.tip_mov = '='
  29. )
  30. if @s_cre_utl is null
  31. begin
  32. set @s_cre_utl = 0
  33. end --if
  34. set @s_dif = (
  35. select
  36. sum(a.pen_ope)
  37. from anlopepen a
  38. inner join anltxt b on
  39. b.cod_emp = a.cod_emp and
  40. b.cod_amb = a.cod_amb and
  41. b.cod_ope = a.cod_ope and
  42. b.cen_ope = a.cen_ope and
  43. b.nro_ope = a.nro_ope and
  44. b.cod_anl = a.cod_anl and
  45. b.cta_anl = a.cta_anl and
  46. b.vto_ope = a.fch_vto and
  47. b.cod_edo = 20 and
  48. b.cod_ref in ('OP.TV', 'REC.TV')
  49. inner join anlcod c on
  50. c.cod_emp = a.cod_emp and
  51. c.cod_amb = a.cod_amb and
  52. c.cod_anl = a.cod_anl and
  53. (@i_cod_dis = ' '
  54. or c.flg_anl = @i_cod_dis)
  55. where 1 = 1
  56. and a.cod_emp = @i_cod_emp
  57. and a.cod_amb = @i_cod_amb
  58. and a.tip_opr = @i_tip_opr
  59. and a.cta_anl = @i_cod_opr
  60. and a.tip_mov = '+'
  61. and a.pen_ope != 0
  62. )
  63. if @s_dif is null
  64. begin
  65. set @s_dif = 0
  66. end --if
  67. return (@s_cre_utl - @s_dif)
  68. return 0
  69. end
  70. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement