Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. drop view `v_ra_status`;
  2. create VIEW `v_ra_status` AS
  3. SELECT
  4. `ct`.`insured_locationID` AS `insured_locationID`,
  5. `ct`.`change_reason` AS `change_reason`,
  6. `msc`.`status_policy_newID` AS `status_policyID`,
  7. `msc`.`status_policy_change_reasonID` AS `status_policy_change_reasonID`,
  8. `msc`.`m_status_changeID` AS `m_status_changeID`,
  9. `sp_new`.`nameNL` AS `ra_statusNL`,
  10. `sp_new`.`nameEN` AS `ra_statusEN`,
  11. `spcr`.`code_change_reason` AS `code_change_reason`,
  12. `spcr`.`nameNL` AS `nameNL`,
  13. `spcr`.`nameEN` AS `nameEN`,
  14. `ct`.`updated` AS `updated`,
  15. `ct`.`due_date` AS `due_date`,
  16. `ct`.`agenda` AS `agenda`,
  17. `ct`.`agenda_tp` AS `agenda_tp`,
  18. `ct`.`remark` AS `remark`,
  19. `ct`.`done` AS `done`,
  20. `ct`.`remark_tp` AS `remark_tp`,
  21. `ct`.`done_tp` AS `done_tp`,
  22. `ct`.`_z_rel_insured_location__m_status_changeID` AS `_z_rel_insured_location__m_status_changeID`
  23. FROM _z_rel_insured_location__m_status_change ct
  24. inner join m_status_change msc on msc.m_status_changeID = ct.m_status_changeID
  25. inner join status_policy sp_new on sp_new.status_policyID = msc.status_policy_newID
  26. inner join status_policy_change_reason spcr on spcr.code_change_reason = msc.status_policy_change_reasonID
  27. order by ct.insured_locationID, ct.updated desc limit 1;
  28.  
  29. If I test it like this:
  30.  
  31. SELECT
  32. `ct`.`insured_locationID` AS `insured_locationID`,
  33. `ct`.`change_reason` AS `change_reason`,
  34. `msc`.`status_policy_newID` AS `status_policyID`,
  35. `msc`.`status_policy_change_reasonID` AS `status_policy_change_reasonID`,
  36. `msc`.`m_status_changeID` AS `m_status_changeID`,
  37. `sp_new`.`nameNL` AS `ra_statusNL`,
  38. `sp_new`.`nameEN` AS `ra_statusEN`,
  39. `spcr`.`code_change_reason` AS `code_change_reason`,
  40. `spcr`.`nameNL` AS `nameNL`,
  41. `spcr`.`nameEN` AS `nameEN`,
  42. `ct`.`updated` AS `updated`,
  43. `ct`.`due_date` AS `due_date`,
  44. `ct`.`agenda` AS `agenda`,
  45. `ct`.`agenda_tp` AS `agenda_tp`,
  46. `ct`.`remark` AS `remark`,
  47. `ct`.`done` AS `done`,
  48. `ct`.`remark_tp` AS `remark_tp`,
  49. `ct`.`done_tp` AS `done_tp`,
  50. `ct`.`_z_rel_insured_location__m_status_changeID` AS `_z_rel_insured_location__m_status_changeID`
  51. FROM _z_rel_insured_location__m_status_change ct
  52. inner join m_status_change msc on msc.m_status_changeID = ct.m_status_changeID
  53. inner join status_policy sp_new on sp_new.status_policyID = msc.status_policy_newID
  54. inner join status_policy_change_reason spcr on spcr.code_change_reason = msc.status_policy_change_reasonID
  55. where ct.insured_locationID = 133918
  56. order by ct.insured_locationID, ct.updated desc limit 1
  57.  
  58. I have one row as expected
  59.  
  60. When I try to use the view like this:
  61.  
  62. select
  63. `ra`.`insured_locationID`,
  64. `vrs`.`status_policyID`
  65. from
  66. `insured_location_c` `ra`
  67. inner join
  68. `v_ra_status` `vrs` ON `vrs`.`insured_locationID` = `ra`.`insured_locationID`
  69. where ra.insured_locationID = 133918
  70.  
  71. I have 0 rows and expected 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement