Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. /*
  2. Duluth Public Schools ISD 709
  3. Query: 1 users.sql
  4. Last Modified: 7/16/2015
  5.  
  6. Desc: Student & Staff
  7. Another routine will likely be needed to
  8. inactivate (set status = complete or delete)
  9. students and staff when necessary (...annual run?).
  10.  
  11. Import sequence: 1 of 6 .csv files
  12. */
  13.  
  14. -- Selects active students for active year, for defined buildings
  15.  
  16. SELECT DISTINCT
  17. u.personID AS 'user_id'
  18. , u.userName AS 'login_id'
  19. -- password ...not needed because we use LDAP for logins
  20. , i.firstName AS 'first_name'
  21. , i.lastName AS 'last_name'
  22. -- full_name - not needed when firstName and lastName
  23. , i.lastName+', '+i.firstname AS 'sortable_name'
  24. , i.firstName AS 'short_name'
  25. , ct.email AS 'email'
  26. , CASE
  27. WHEN en.endDate IS NULL THEN 'active'
  28. ELSE 'deleted'
  29. END AS 'status'
  30. --, en.endDate
  31.  
  32. FROM Person p
  33. JOIN [Identity] i ON i.identityID = p.currentIdentityID
  34. JOIN UserAccount u ON u.personID = p.personID
  35. LEFT JOIN Enrollment en ON en.personID = p.personID AND en.endDate IS NULL --> GETDATE ()
  36. JOIN Calendar ca ON ca.calendarID = en.calendarID AND ca.schoolID IN (44,29,4,5,51,7)
  37. JOIN SchoolYear sy ON sy.endYear = en.endYear and sy.active = 1
  38. LEFT JOIN Contact ct ON ct.personID = p.personID --for email
  39.  
  40. WHERE
  41. p.studentNumber IS NOT NULL
  42.  
  43. UNION
  44.  
  45. -- Selects active lisenced staff, for active year, for defined buildings
  46. SELECT DISTINCT
  47. p.personID AS 'user_id'
  48. , ua.username AS 'login_id'
  49. , i.firstName AS 'first_name'
  50. , i.lastName AS 'last_name'
  51. , i.lastName +', '+i.firstName AS 'sortable_name'
  52. , i.firstName AS 'short_name'
  53. , ct.email AS 'email'
  54. , CASE
  55. WHEN em.endDate IS NULL THEN 'active'
  56. ELSE 'deleted'
  57. END AS 'status'
  58. --, em.endDate
  59.  
  60.  
  61. FROM person p
  62. JOIN [Identity] i ON i.identityID = p.currentIdentityID
  63. JOIN UserAccount ua ON ua.personID = p.personID
  64. JOIN employment em ON em.personID = p.personID
  65. JOIN EmploymentAssignment ea ON ea.personID = p.personID
  66. LEFT JOIN Contact ct ON ct.personID = p.personID --for email
  67. WHERE p.staffNumber IS NOT NULL
  68. --AND em.endDate IS NULL --this line would only allow extracting active employees!
  69. AND em.licenseNumber IS NOT NULL
  70. AND ua.userName NOT LIKE '%_709'
  71. AND ua.homepage NOT LIKE 'portal%'
  72. AND ua.userName NOT LIKE '%schedule'
  73. AND ua.userName NOT LIKE 'sped%'
  74. AND ea.schoolID IN (4,5,51,7,29,44)
  75.  
  76. ORDER BY login_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement