Guest User

Untitled

a guest
Nov 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. Create Proc pru_conve_prestaciones (
  2. @conve integer ,
  3. @nomen tinyint ,
  4. @prestac char(10) ,
  5. @alta_fecha smalldatetime ,
  6. @baja_fecha smalldatetime =null ,
  7. @listaconcep varchar(255) ,
  8. @listaesta varchar(255) ,
  9. @listatotal smallint
  10. )
  11. As
  12. Begin
  13. /**********************************************************
  14. *Procedure Name: pru_conve_prestaciones
  15. *Database: Prestaci
  16. *Server:
  17. *SQL-BuilderR3.8
  18. *File Path:
  19. * R:\SISTEMAS\PresMed\Sp\pru_conve_prestaciones.PRO
  20. *********************************************************/
  21.  
  22. declare @vigen_desde smalldatetime,@concep tinyint,
  23. @item smallint,@conve_prestac integer,@esta char(1),
  24. @vigen_desde2 smalldatetime
  25. select @item=1
  26. while @item<=@listatotal
  27. begin
  28. select @concep=convert(tinyint,substring(@listaconcep,(@item-1)*2+1,2))
  29. select @esta=substring(@listaesta,@item,1)
  30. select @conve_prestac=null
  31. select @conve_prestac=conve_prestac
  32. from conve_prestaciones
  33. where conve=@conve
  34. and prestac=@prestac
  35. and nomen=@nomen
  36. and concep=@concep
  37. if ( @esta='B' or @baja_fecha is not null ) and
  38. @conve_prestac>0
  39. begin
  40. /* baja de la prestac en el convenio */
  41. update conve_prestaciones
  42. set baja_fecha=getdate()
  43. where conve_prestac=@conve_prestac
  44.  
  45. update conve_odon_reglas
  46. set baja_fecha=getdate()
  47. where conve_prestac=@conve_prestac
  48. and baja_fecha is null
  49.  
  50. update conve_prestac_valores set
  51. baja_fecha=getdate()
  52. where conve_prestac=@conve_prestac
  53. and baja_fecha is null
  54.  
  55. update conve_normas set
  56. baja_fecha=getdate()
  57. where conve=@conve
  58. and nomen=@nomen
  59. and prestac=@prestac
  60. and inter_sala=0
  61. and baja_fecha is null
  62.  
  63. end
  64. else
  65. if @esta='A' and @baja_fecha is null
  66. begin
  67. /* alta o modif de la prestac en el convenio */
  68. if @conve_prestac is null
  69. begin
  70. update parametros
  71. set conve_prestac=conve_prestac+1
  72. select @conve_prestac=conve_prestac
  73. from parametros
  74. insert into conve_prestaciones(conve_prestac,
  75. conve,
  76. nomen,
  77. prestac,
  78. alta_fecha,
  79. baja_fecha,
  80. concep)
  81. values(@conve_prestac,
  82. @conve,
  83. @nomen,
  84. @prestac,
  85. @alta_fecha,
  86. null,
  87. @concep)
  88.  
  89. end
  90. else
  91. update conve_prestaciones set
  92. baja_fecha=null
  93. where conve_prestac=@conve_prestac
  94. /* Si el convenio ya tenia valores para esa prestacion
  95. pero con otro concepto,completo con 0.01 */
  96. if not exists(select *
  97. from conve_prestac_valores
  98. where conve_prestac=@conve_prestac
  99. and baja_fecha is null)
  100. begin
  101. select @vigen_desde2=max(a.vigen_desde)
  102. from conve_prestac_valores a, conve_prestaciones b
  103. where a.conve_prestac=b.conve_prestac
  104. and a.baja_fecha is null
  105. and b.conve=@conve
  106. and b.nomen=@nomen
  107. and b.prestac=@prestac
  108. and b.concep<>@concep
  109.  
  110. if @vigen_desde2 is not null
  111. begin
  112. update conve_prestac_valores
  113. set baja_fecha=null,
  114. valor=0.01,
  115. porce_mas=null,
  116. porce_menos=null,
  117. valor_multi=null,
  118. urgen_diurna=null,
  119. urgen_noctur=null,
  120. vier_plus=null
  121. where conve_prestac=@conve_prestac
  122. and vigen_desde=@vigen_desde2
  123. if @@rowcount=0
  124. insert into conve_prestac_valores
  125. select @conve_prestac,@vigen_desde2,
  126. null,null,null,0.01,null,null,null,null,null,null
  127. end
  128. end
  129. end
  130. select @item = @item + 1
  131. end
  132.  
  133.  
  134.  
  135. End
Add Comment
Please, Sign In to add comment