Advertisement
vikowijaya

Query Setelah Di pikir pikir

Oct 16th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. insert into [SMI.Monitoring].[dbo].general_detail
  2.  
  3. SELECT T.ID, T.Process_ID, T.Activity_ID, T.Transaction_ID, T.Outcome, T.Remark, T.Actioner,
  4. T.ActionDate, T.Orig_Dest, T.Task_Received_Date, T.Process_Name, T.Employee_Name,
  5. T.Activity_Name, T.Action_Name,
  6. case
  7. when PrevDate is null then 0
  8. else DATEDIFF("n", PrevDate,ActionDate)
  9. end as time_diff,
  10. case
  11. when (convert (bigint, (DATEDIFF("n", PrevDate,ActionDate))) > T.sla) then 1
  12. else 0
  13. end as is_meet_sla,
  14. case
  15. when(convert (bigint, (DATEDIFF("n", PrevDate,ActionDate))) > T.threshold) then 2
  16. when(convert (bigint, (DATEDIFF("n", PrevDate,ActionDate))) = T.threshold) then 1
  17. when(convert (bigint, (DATEDIFF("n", PrevDate,ActionDate))) < T.threshold) then 0
  18. end as is_meet_threshold,
  19. T.is_finish
  20. FROM ( SELECT *,
  21. ( SELECT MAX(ActionDate)
  22. FROM [SMI.Monitoring].[dbo].[temp_general_detail] T2
  23. WHERE T2.Transaction_ID = T1.Transaction_ID
  24. AND T2.ActionDate < T1.ActionDate
  25. ) AS PrevDate,
  26. ( select sla from [SMI.Monitoring].dbo.sla_param where sla_param.sla_desc = Activity_Name AND sla_param.jenis_dokumen = 'Nota Dinas Masuk' ) as sla,
  27. ( select threshold from [SMI.Monitoring].dbo.sla_param where sla_param.sla_desc = Activity_Name AND sla_param.jenis_dokumen = 'Nota Dinas Masuk' ) as threshold,
  28. ( select is_last_state from [SMI.Monitoring].dbo.sla_param where sla_param.sla_desc = Activity_Name AND sla_param.jenis_dokumen = 'Nota Dinas Masuk' ) as is_finish
  29. FROM [SMI.Monitoring].[dbo].[temp_general_detail] T1
  30. WHERE Process_ID in (7)
  31. ) AS T
  32. WHERE not exists ( select ID from [SMI.Monitoring].[dbo].general_detail where ID = T.ID)
  33. order by Transaction_ID, ActionDate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement