Advertisement
Guest User

Untitled

a guest
May 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. WHERE
  2. a.parent_id = 391
  3. and a.child_id = 481
  4. and cm.customer_id <> -1
  5. and a.activity_date >= trunc(sysdate)-15
  6. and cm.current_flag = 'Y'
  7. and cases.id = (SELECT max(cases2.id) from tallyman_mis.mis_cases cases2 WHERE cases.tallyman_case_id = cases2.tallyman_case_id) /*Only uses most current version of the case. Prevents dupes on Green_Forms_ID*/
  8.  
  9. GROUP BY
  10. cm.customer_id
  11. ,a.activity_date
  12. ,a.tallyman_case_id
  13. ,c.anz_id
  14. ,cm.is_lead_customer
  15. ,u.forename
  16. ,u.Email_Address
  17. ,a.customer_id
  18. ,cases.green_forms_id
  19. ,cases.case_name
  20.  
  21. ) t1
  22.  
  23. LEFT JOIN
  24. (
  25. SELECT
  26. a.id Activity_ID
  27. ,a.activity_date Full_Date
  28. ,a.tallyman_case_id Case_ID
  29. ,cd.setcode Set_Code
  30. ,cd.branchcd Branch
  31. ,c.anz_id RM
  32. ,u.Email_Address Case_Manager_Email
  33. ,a.customer_id
  34. ,c.anz_id
  35.  
  36. FROM
  37. Tallyman_mis.mis_activities a
  38. LEFT JOIN tallyman_mis.col_details cd
  39. ON cd.accounts1 = a.customer_id
  40. LEFT JOIN tallyman_mis.mis_customers c /*Get all account numbers in case*/
  41. ON c.id = a.customer_id
  42. LEFT JOIN tallyman_mis.mis_users u
  43. on u.id = a.activity_user
  44.  
  45. WHERE
  46. a.parent_id in 1
  47. and a.child_id = 83 /*Set change activity*/
  48. and a.activity_date >= trunc(sysdate)-15
  49. and a.tallyman_case_id <> -1
  50. and c.anz_id is not null
  51. and cd.branchcd is not null
  52. )f1
  53. ON f1.Full_Date = t1.Full_Date
  54. and f1.Case_ID = t1.Case_ID
  55. and f1.RM = t1.RM
  56.  
  57. WHERE
  58. t1.case_id is not null
  59.  
  60. GROUP BY
  61. t1.Full_Date
  62. ,t1.case_name
  63. ,t1.Case_ID
  64. ,t1.RM
  65. ,t1.is_lead_customer
  66. ,f1.Set_Code
  67. ,f1.Branch
  68. ,t1.Case_Manager
  69. ,t1.Case_Manager_Email
  70. ,t1.green_forms_id
  71. ,t1.Written_Off_Arrears
  72. ,t1.Provision_Account
  73.  
  74. ORDER BY
  75. t1.Case_ID
  76. ,t1.is_lead_customer desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement