Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1.  
  2. select r.id
  3. ,b.from_dt
  4. ,b.to_dt
  5. , proom.name||', койка №'||b.number||coalesce(', '||bprof.name,'')||', '||dep.name,
  6. bprof.id as bed_profile, bprof.name as bed_profile_name
  7. 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
  8. join pim_room proom on room.id = proom.id
  9. left join md_bed_profile bprof on b.bed_profile_id=bprof.id
  10. join pim_department dep on proom.department_id = dep.id
  11. join pim_organization org on dep.org_id = org.id where upper(proom.name||', койка №'||b.number||coalesce(', '||bprof.name,'')||', '||dep.name) like '%'||upper('')||'%'
  12. and org.id = 123 and (dep.id = 1293)
  13. and (
  14. to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy hh24:mi:ss')::timestamp is null and 13264557::int4 is null or
  15. to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp is null
  16. or
  17. not exists
  18. (
  19. select 1 from sr_res_group_relationship rgrel where rgrel.resource_id = r.id and
  20. exists(select 1 from mc_step s where s.res_group_id = rgrel.group_id) and
  21. (not
  22. (
  23. (
  24. 13264557::int4 is not null and
  25. (select max(edatetime) from sr_res_group_relationship where group_id = 13264557 and
  26. role_id in (select id from sr_res_role where resource_kind_id = 4)) > rgrel.edatetime
  27. or
  28. to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy hh24:mi:ss')::timestamp > rgrel.edatetime
  29. ) or
  30. to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp < rgrel.bdatetime
  31. )
  32. or to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy hh24:mi:ss')::timestamp > rgrel.bdatetime and rgrel.edatetime is null
  33. )
  34. )
  35. )
  36.  
  37. /*
  38. and (
  39. (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')))
  40. 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')))
  41. or (b.to_dt is null and b.from_dt is null)
  42. or (b.from_dt <= coalesce(to_timestamp('29.10.2016 18:50', 'dd.MM.yyyy'), to_date('26.03.2017','dd.mm.yyyy'))
  43. and b.to_dt >= coalesce(to_timestamp('08.11.2016 13:44', 'dd.MM.yyyy'), to_date('26.03.2017 ','dd.mm.yyyy')))
  44. )
  45. */
  46. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement