Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. select
  2. movement.movementid, (endcall-startcall) AS duracion,
  3. nombre||' '||apellido AS usuario, movement.description AS desc, destination.name as destination, client.name as client, fromnumber, (case when movement.moment is null then movement.validfrom::timestamp else movement.moment end) as moment, amount, (case when startcall is null then validfrom else startcall end), (case when endcall is null then validto else endcall end), tonumber,
  4. targetlocation.country as pais, targetlocation.city as ciudad, targetlocation.group as grupo
  5. from movement
  6. left join targetlocation on targetlocation.targetid=movement.targetid
  7. inner join clientbag on clientbag.clientbagid=movement.clientbagid
  8. inner join client on client.clientid=clientbag.clientid
  9. inner join peerclientbag on peerclientbag.clientbagid=clientbag.clientbagid
  10. inner join peer on peer.peerid=peerclientbag.peerid
  11. inner join product on product.productid=peer.productid
  12. left join cdr on cdr.cdrid=movement.cdrid
  13. left join movementorigin on movementorigin.movementid=movement.movementid
  14. left join recurso on recurso.recursoid=movementorigin.recursoid
  15. left join destination on destination.destinationid=move ment.destinationid
  16.  
  17.  
  18. where
  19.  
  20. case when '{%dteFechaDesdeFiltro%}' <> '1900-01-01' and '{%dteFechaHastaFiltro%}' = '1900-01-01' then
  21. (case when movement.moment is null then movement.validfrom::timestamp else movement.moment end)::date >= '{%dteFechaDesdeFiltro%}'
  22. and case when destination.name is null then '' else destination.name end ilike '{%strDestinationFiltro%}%'
  23.  
  24. and (case when fromnumber is not null then fromnumber ilike '{%strNumeroFiltro%}%' else '' = '' end)
  25. and peer.number ilike '{%strNumeroFiltro%}%'
  26. and client.name ilike '{%strClienteFiltro%}%'
  27. and (case when '{%cmbUsuarioFiltro%}' = '' then '' = ''
  28. else recurso.recursoid ilike '{%cmbUsuarioFiltro%}' end)
  29. and (case when '{%cmbMedioFiltro%}' = '' then '' = ''
  30. else rechargemediaid ilike '{%cmbMedioFiltro%}' end)
  31. and (case when '{%cmbReseller%}' = '' then '' = ''
  32. else client.resellerid ilike '{%cmbReseller%}' end)
  33. and producttypeid=1
  34. and movement.description ilike '{%strDescripcionFiltro%}%'
  35. and client.resellerid in (select resellerid from recursoreseller where recursoid = [%USUARIO%])
  36.  
  37. when '{%dteFechaDesdeFiltro%}' = '1900-01-01' and '{%dteFechaHastaFiltro%}' <> '1900-01-01' then
  38. (case when movement.moment is null then movement.validfrom::timestamp else movement.moment end)::date <= '{%dteFechaHastaFiltro%}'
  39. and case when destination.name is null then '' else destination.name end ilike '{%strDestinationFiltro%}%'
  40.  
  41. and (case when fromnumber is not null then fromnumber ilike '{%strNumeroFiltro%}%' else '' = '' end)
  42. and peer.number ilike '{%strNumeroFiltro%}%'
  43. and client.name ilike '{%strClienteFiltro%}%'
  44. and (case when '{%cmbUsuarioFiltro%}' = '' then '' = ''
  45. else recurso.recursoid ilike '{%cmbUsuarioFiltro%}' end)
  46. and (case when '{%cmbMedioFiltro%}' = '' then '' = ''
  47. else rechargemediaid ilike '{%cmbMedioFiltro%}' end)
  48. and (case when '{%cmbReseller%}' = '' then '' = ''
  49. else client.resellerid ilike '{%cmbReseller%}' end)
  50. and producttypeid=1
  51. and movement.description ilike '{%strDescripcionFiltro%}%'
  52. and client.resellerid in (select resellerid from recursoreseller where recursoid = [%USUARIO%])
  53.  
  54. when '{%dteFechaDesdeFiltro%}'<> '1900-01-01' and '{%dteFechaHastaFiltro%}' <> '1900-01-01' then
  55. (case when movement.moment is null then movement.validfrom::timestamp else movement.moment end)::date BETWEEN '{%dteFechaDesdeFiltro%}' and '{%dteFechaHastaFiltro%}'
  56. and case when destination.name is null then '' else destination.name end ilike '{%strDestinationFiltro%}%'
  57.  
  58. and (case when fromnumber is not null then fromnumber ilike '{%strNumeroFiltro%}%' else '' = '' end)
  59. and peer.number ilike '{%strNumeroFiltro%}%'
  60. and client.name ilike '{%strClienteFiltro%}%'
  61. and (case when '{%cmbUsuarioFiltro%}' = '' then '' = ''
  62. else recurso.recursoid ilike '{%cmbUsuarioFiltro%}' end)
  63. and (case when '{%cmbMedioFiltro%}' = '' then '' = ''
  64. else rechargemediaid ilike '{%cmbMedioFiltro%}' end)
  65. and (case when '{%cmbReseller%}' = '' then '' = ''
  66. else client.resellerid ilike '{%cmbReseller%}' end)
  67. and producttypeid=1
  68. and movement.description ilike '{%strDescripcionFiltro%}%'
  69. and client.resellerid in (select resellerid from recursoreseller where recursoid = [%USUARIO%])
  70.  
  71. when '{%dteFechaDesdeFiltro%}'= '1900-01-01' and '{%dteFechaHastaFiltro%}' = '1900-01-01' then
  72.  
  73. (case when fromnumber is not null then fromnumber ilike '{%strNumeroFiltro%}%' else '' = '' end)
  74. and case when destination.name is null then '' else destination.name end ilike '{%strDestinationFiltro%}%'
  75. and peer.number ilike '{%strNumeroFiltro%}%'
  76. and client.name ilike '{%strClienteFiltro%}%'
  77. and (case when '{%cmbUsuarioFiltro%}' = '' then '' = ''
  78. else recurso.recursoid ilike '{%cmbUsuarioFiltro%}' end)
  79. and (case when '{%cmbMedioFiltro%}' = '' then '' = ''
  80. else rechargemediaid ilike '{%cmbMedioFiltro%}' end)
  81. and (case when '{%cmbReseller%}' = '' then '' = ''
  82. else client.resellerid ilike '{%cmbReseller%}' end)
  83. and producttypeid=1
  84. and movement.description ilike '{%strDescripcionFiltro%}%'
  85. and client.resellerid in (select resellerid from recursoreseller where recursoid = [%USUARIO%])
  86.  
  87. END
  88.  
  89.  
  90. order by (case when movement.moment is null then movement.validfrom::timestamp else movement.moment end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement