Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. select r.id
  2. ,b.from_dt
  3. ,b.to_dt
  4. , proom.name||', койка №'||b.number||coalesce(', '||bprof.name,'')||', '||dep.name,
  5. bprof.id as bed_profile, bprof.name as bed_profile_name
  6. FROM md_bed_resource AS r INNER JOIN md_bed AS b ON r.bed_id = b.id join md_room room on b.room_id = room.id
  7. join pim_room proom on room.id = proom.id
  8. left join md_bed_profile bprof on b.bed_profile_id=bprof.id
  9. join pim_department dep on proom.department_id = dep.id
  10. join pim_organization org on dep.org_id = org.id where upper(proom.name||', койка №'||b.number||coalesce(', '||bprof.name,'')||', '||dep.name) like '%'||upper('')||'%'
  11. and org.id = 123 and (dep.id = 1293)
  12. and (
  13. to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy hh24:mi:ss')::timestamp is null and 13264557::int4 is null or
  14. to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp is null
  15. or
  16. not exists
  17. (
  18. select 1 from sr_res_group_relationship rgrel where rgrel.resource_id = r.id and
  19. exists(select 1 from mc_step s where s.res_group_id = rgrel.group_id) and
  20. (not
  21. (
  22. (
  23. 13264557::int4 is not null and
  24. (select max(edatetime) from sr_res_group_relationship where group_id = 13264557 and
  25. role_id in (select id from sr_res_role where resource_kind_id = 4)) > rgrel.edatetime
  26. or
  27. to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy hh24:mi:ss')::timestamp > rgrel.edatetime
  28. ) or
  29. to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp < rgrel.bdatetime
  30. )
  31. or to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp > rgrel.bdatetime and rgrel.edatetime is null
  32. )
  33. )
  34. )
  35.  
  36. /*
  37. and (
  38. (b.from_dt is null and b.to_dt >= coalesce(to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy'), to_date('26.03.2017','dd.mm.yyyy')))
  39. or (b.to_dt is null and b.from_dt <= coalesce(to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy'), to_date('26.03.2017','dd.mm.yyyy')))
  40. or (b.to_dt is null and b.from_dt is null)
  41. or (b.from_dt <= coalesce(to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy'), to_date('26.03.2017','dd.mm.yyyy'))
  42. and b.to_dt >= coalesce(to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy'), to_date('26.03.2017 ','dd.mm.yyyy')))
  43. )
  44. */
  45. ;
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. select r.id
  53. ,b.from_dt
  54. ,b.to_dt
  55. , proom.name||', койка №'||b.number||coalesce(', '||bprof.name,'')||', '||dep.name,
  56. bprof.id as bed_profile, bprof.name as bed_profile_name
  57. FROM md_bed_resource AS r INNER JOIN md_bed AS b ON r.bed_id = b.id join md_room room on b.room_id = room.id
  58. join pim_room proom on room.id = proom.id
  59. left join md_bed_profile bprof on b.bed_profile_id=bprof.id
  60. join pim_department dep on proom.department_id = dep.id
  61. join pim_organization org on dep.org_id = org.id where upper(proom.name||', койка №'||b.number||coalesce(', '||bprof.name,'')||', '||dep.name) like '%'||upper('')||'%'
  62. and org.id = 123 and (dep.id = 1293)
  63. and (
  64. to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy hh24:mi:ss')::timestamp is null and null::int4 is null or
  65. to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp is null
  66. or
  67. not exists
  68. (
  69. select 1 from sr_res_group_relationship rgrel where rgrel.resource_id = r.id and
  70. exists(select 1 from mc_step s where s.res_group_id = rgrel.group_id) and
  71. (not
  72. (
  73. (
  74. null::int4 is not null and
  75. (select max(edatetime) from sr_res_group_relationship where group_id = 13264557 and
  76. role_id in (select id from sr_res_role where resource_kind_id = 4)) > rgrel.edatetime
  77. or
  78. to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy hh24:mi:ss')::timestamp > rgrel.edatetime
  79. ) or
  80. to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp < rgrel.bdatetime
  81. )
  82. or to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp > rgrel.bdatetime and rgrel.edatetime is null
  83. )
  84. )
  85. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement