Guest User

Untitled

a guest
Oct 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. StartDate EndDate ID
  2. 04/01/2017 06/30/2017 1
  3. 10/01/2017 1
  4. 11/01/2017 05/01/2017 2
  5.  
  6. StartDate EndDate ID CurrentStatus
  7. 04/01/2017 06/30/2017 1 Active
  8. 10/01/2017 1 Active
  9. 11/01/2017 11/02/2017 2 Closed
  10.  
  11. SELECT *
  12. MAX(CASE WHEN CCP.ENDDATE IS NULL THEN 'Active' END)
  13. OVER (PARTITION BY CCP.ID) AS CURRENT_STATUS
  14. FROM TABLEA CCP
  15.  
  16. SELECT *
  17. coalesce(MAX(CASE WHEN CCP.ENDDATE IS NULL THEN 'Active' END)
  18. OVER (PARTITION BY CCP.ID),'Closed') AS CURRENT_STATUS
  19. FROM TABLEA CCP
  20.  
  21. SELECT A1.StartDate
  22. , A1.EndDate
  23. , A1.ID
  24. , case when A2.ID is not null then 'Active' Else 'Closed' end As currentStatus
  25. FROM TableA A1
  26. INNER JOIN (SELECT Distinct ID
  27. FROM TableA
  28. WHERE EndDate is null or EndDate>=Sysdate()) A2
  29. on A1.ID = A2.ID
Add Comment
Please, Sign In to add comment