Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. select 1 ,'0782300202'+
  2. cast(year(getdate()) as varchar)+
  3. right(100+month(getdate()),2)+
  4. right(100+day(getdate()+1),2)+
  5. 'SERVIPAG'+
  6. right(cast((COUNT(saldo)+1000000000) as varchar),6) +
  7. right(cast((sum(montoTotal)+1000000000000000) As numeric),14)+ ' ' as col1
  8. from
  9. (
  10. select saldo,
  11. case -- monto: SUMA EL SALDO MAS LOS INTERESES Y SI LA DIF EN DIAS ES > 30 TAMBIEN LO SUMA
  12. when DATEDIFF(day,fecha_vencimiento,getdate())<= 5 then
  13. saldo
  14. when DATEDIFF(day,fecha_vencimiento,getdate())between 6 and 30 then
  15. RIGHT(cast(saldo+1000000000000+cast(round((((saldo*1.2)/100)/30)*(DATEDIFF(day,fecha_vencimiento,getdate())-5),0) as numeric) as varchar),8)
  16. when DATEDIFF(day,fecha_vencimiento,getdate())>30 then
  17. saldo+round(((saldo*5)/100),0)+
  18. (round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0))
  19. else -- SUMA EL SALDO MAS LOS INTERESES (no contempla g.cobrazas)
  20. saldo
  21.  
  22. end
  23. as montoTotal
  24. from servipag)
  25. x
  26. -- + ' ' from servipag
  27.  
  28. union
  29.  
  30. select 2
  31. rut,right('000'+substring(rut,1,len(rut)-2),10)+right('000'+substring(rut,1,len(rut)-2),10)+ SUBSTRING(rut,LEN(rut),1)+
  32. '00000000000000000000'+ -- DIRECCION
  33. '3'+ -- TIPO DOCUMENTO
  34. RIGHT(cast(numero_cuota+10000000000000 as varchar),12)+ -- NUMERO DE DOCUMENTO
  35. --case -- monto: fecha proxima a vencer
  36. --when DATEDIFF(day,fecha_vencimiento,getdate())<= 0 then
  37. --cast(cast((saldo+0) As numeric)AS varchar)
  38. --end+
  39. case -- monto: SUMA EL SALDO MAS LOS INTERESES Y SI LA DIF EN DIAS ES > 30 TAMBIEN LO SUMA
  40. when DATEDIFF(day,fecha_vencimiento,getdate())<= 5 then
  41. right(cast(cast((saldo+10000000000000) As numeric)AS varchar),8)
  42. when DATEDIFF(day,fecha_vencimiento,getdate())between 6 and 30 then
  43. RIGHT(cast(saldo+1000000000000+cast(round((((saldo*1.2)/100)/30)*(DATEDIFF(day,fecha_vencimiento,getdate())-5),0) as numeric) as varchar),8)
  44. when DATEDIFF(day,fecha_vencimiento,getdate())>30 then
  45. RIGHT(cast(saldo+10000000000000+cast(round(((saldo*5)/100),0) as numeric)+
  46. cast(round((((saldo*1.2)/100)/30)*(DATEDIFF(day,fecha_vencimiento,getdate())-5),0) as numeric) as varchar),8)
  47. else -- SUMA EL SALDO MAS LOS INTERESES (no contempla g.cobrazas)
  48.  
  49. right(cast(cast((saldo+10000000000000) As numeric)AS varchar),8)
  50. end+
  51. '00000000'+ -- SALDO ANTERIOR
  52. cast(year(fecha_vencimiento) as varchar)+right(cast((month(fecha_vencimiento))+100 as varchar),2)+right(cast((100+day(fecha_vencimiento)) as varchar),2)+ -- FECHA VCTO YYYYMMAA
  53. case -- CALCULO interes
  54. when DATEDIFF(day,fecha_vencimiento,getdate())<=0 then '00000000'
  55. when DATEDIFF(day,fecha_vencimiento,getdate())>=6 then right(cast(round((((saldo*1.2)/100)/30)*(DATEDIFF(day,fecha_vencimiento,getdate())-5),0) as numeric)+1000000000,8)
  56. end +
  57. case -- CALCULO G.cobranzas
  58. when DATEDIFF(day,fecha_vencimiento,getdate())<=30 then '00000000'
  59. when DATEDIFF(day,fecha_vencimiento,getdate())>30 then right(cast(round((((saldo*5)/100)),0) as numeric)+1000000000,8)
  60. end+
  61. --'0'+
  62. --right(numeral_cuota,2)+ -- NÚMERO DE CUOTA
  63. RIGHT(cast(numeral_cuota+100000 as varchar),3)+
  64. RIGHT(cast(saldo+10000000000000 as varchar),8)-- SALDO
  65. as col1
  66. from servipag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement