Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- begin
- declare @s_cre_utl decimal(18,2)
- declare @s_dif decimal(18,2)
- set @s_cre_utl = 0
- set @s_dif = 0
- set @s_cre_utl = (
- select
- sum(b.dal_ope)
- from anlsdo b
- inner join anlcod a on
- a.cod_emp = b.cod_emp and
- a.cod_amb = b.cod_amb and
- a.cod_anl = b.cod_anl and
- (@i_cod_dis = ' '
- or a.flg_anl = @i_cod_dis)
- inner join concta n on
- n.cod_emp = a.cod_emp and
- n.cod_amb = a.cod_amb and
- n.cod_cta = a.cod_cta and
- n.tip_res != 'S'
- where 1 = 1
- and b.cod_emp = @i_cod_emp
- and b.cod_amb = @i_cod_amb
- and b.tip_opr = @i_tip_opr
- and b.cta_anl = @i_cod_opr
- and b.tip_mov = '='
- )
- if @s_cre_utl is null
- begin
- set @s_cre_utl = 0
- end --if
- set @s_dif = (
- select
- sum(a.pen_ope)
- from anlopepen a
- inner join anltxt b on
- b.cod_emp = a.cod_emp and
- b.cod_amb = a.cod_amb and
- b.cod_ope = a.cod_ope and
- b.cen_ope = a.cen_ope and
- b.nro_ope = a.nro_ope and
- b.cod_anl = a.cod_anl and
- b.cta_anl = a.cta_anl and
- b.vto_ope = a.fch_vto and
- b.cod_edo = 20 and
- b.cod_ref in ('OP.TV', 'REC.TV')
- inner join anlcod c on
- c.cod_emp = a.cod_emp and
- c.cod_amb = a.cod_amb and
- c.cod_anl = a.cod_anl and
- (@i_cod_dis = ' '
- or c.flg_anl = @i_cod_dis)
- where 1 = 1
- and a.cod_emp = @i_cod_emp
- and a.cod_amb = @i_cod_amb
- and a.tip_opr = @i_tip_opr
- and a.cta_anl = @i_cod_opr
- and a.tip_mov = '+'
- and a.pen_ope != 0
- )
- if @s_dif is null
- begin
- set @s_dif = 0
- end --if
- return (@s_cre_utl - @s_dif)
- return 0
- end
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement