Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create Proc pru_conve_prestaciones (
- @conve integer ,
- @nomen tinyint ,
- @prestac char(10) ,
- @alta_fecha smalldatetime ,
- @baja_fecha smalldatetime =null ,
- @listaconcep varchar(255) ,
- @listaesta varchar(255) ,
- @listatotal smallint
- )
- As
- Begin
- /**********************************************************
- *Procedure Name: pru_conve_prestaciones
- *Database: Prestaci
- *Server:
- *SQL-BuilderR3.8
- *File Path:
- * R:\SISTEMAS\PresMed\Sp\pru_conve_prestaciones.PRO
- *********************************************************/
- declare @vigen_desde smalldatetime,@concep tinyint,
- @item smallint,@conve_prestac integer,@esta char(1),
- @vigen_desde2 smalldatetime
- select @item=1
- while @item<=@listatotal
- begin
- select @concep=convert(tinyint,substring(@listaconcep,(@item-1)*2+1,2))
- select @esta=substring(@listaesta,@item,1)
- select @conve_prestac=null
- select @conve_prestac=conve_prestac
- from conve_prestaciones
- where conve=@conve
- and prestac=@prestac
- and nomen=@nomen
- and concep=@concep
- if ( @esta='B' or @baja_fecha is not null ) and
- @conve_prestac>0
- begin
- /* baja de la prestac en el convenio */
- update conve_prestaciones
- set baja_fecha=getdate()
- where conve_prestac=@conve_prestac
- update conve_odon_reglas
- set baja_fecha=getdate()
- where conve_prestac=@conve_prestac
- and baja_fecha is null
- update conve_prestac_valores set
- baja_fecha=getdate()
- where conve_prestac=@conve_prestac
- and baja_fecha is null
- update conve_normas set
- baja_fecha=getdate()
- where conve=@conve
- and nomen=@nomen
- and prestac=@prestac
- and inter_sala=0
- and baja_fecha is null
- end
- else
- if @esta='A' and @baja_fecha is null
- begin
- /* alta o modif de la prestac en el convenio */
- if @conve_prestac is null
- begin
- update parametros
- set conve_prestac=conve_prestac+1
- select @conve_prestac=conve_prestac
- from parametros
- insert into conve_prestaciones(conve_prestac,
- conve,
- nomen,
- prestac,
- alta_fecha,
- baja_fecha,
- concep)
- values(@conve_prestac,
- @conve,
- @nomen,
- @prestac,
- @alta_fecha,
- null,
- @concep)
- end
- else
- update conve_prestaciones set
- baja_fecha=null
- where conve_prestac=@conve_prestac
- /* Si el convenio ya tenia valores para esa prestacion
- pero con otro concepto,completo con 0.01 */
- if not exists(select *
- from conve_prestac_valores
- where conve_prestac=@conve_prestac
- and baja_fecha is null)
- begin
- select @vigen_desde2=max(a.vigen_desde)
- from conve_prestac_valores a, conve_prestaciones b
- where a.conve_prestac=b.conve_prestac
- and a.baja_fecha is null
- and b.conve=@conve
- and b.nomen=@nomen
- and b.prestac=@prestac
- and b.concep<>@concep
- if @vigen_desde2 is not null
- begin
- update conve_prestac_valores
- set baja_fecha=null,
- valor=0.01,
- porce_mas=null,
- porce_menos=null,
- valor_multi=null,
- urgen_diurna=null,
- urgen_noctur=null,
- vier_plus=null
- where conve_prestac=@conve_prestac
- and vigen_desde=@vigen_desde2
- if @@rowcount=0
- insert into conve_prestac_valores
- select @conve_prestac,@vigen_desde2,
- null,null,null,0.01,null,null,null,null,null,null
- end
- end
- end
- select @item = @item + 1
- end
- End
Add Comment
Please, Sign In to add comment