Guest User

Untitled

a guest
Sep 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. USE [Payroll]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[EmployeeProfitability] Script Date: 9/23/2018 7:34:12 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. ALTER PROCEDURE [dbo].[EmployeeProfitability]
  10. @PayrollDate DateTime
  11.  
  12. AS
  13. BEGIN
  14.  
  15. SELECT 0 AS Id, FirstName, LastName,
  16. Volume.Volume AS Volume,
  17. Volume.MaterialPct AS MaterialPct,
  18. Volume.LaborPct AS LaborPct,
  19. Volume.ProfitPct AS ProfitPct,
  20. Volume.Systems AS Systems,
  21. Volume.AOR AS AOR,
  22. Volume.Upgrade AS Upgrade,
  23. Volume.Condemned AS Condemned,
  24. Volume.TravelTime AS TravelTime,
  25. Volume.RegularHours AS RegularHours,
  26. Volume.OvertimeHours AS OvertimeHours
  27. from dbo.Employees e
  28. LEFT JOIN (
  29. SELECT EmployeeId,
  30. SUM(Billing) AS Volume,
  31. SUM(Billing) / SUM(MaterialCost) AS MaterialPct,
  32. SUM(Billing) / SUM(Pay) AS LaborPct,
  33. SUM(Billing) / SUM(Profit) AS ProfitPct,
  34. SUM(System) AS Systems,
  35. SUM(AOR) AS AOR,
  36. SUM(Upgrade) AS Upgrade,
  37. SUM(Condemned) AS Condemned,
  38. SUM(TravelMinutes) AS TravelTime,
  39. SUM(RegularHours) AS RegularHours,
  40. SUM(OvertimeHours) AS OvertimeHours
  41. FROM dbo.EmployeeJobs ej
  42. WHERE PayrollDate = @PayrollDate
  43. GROUP BY ej.EmployeeId
  44. ) AS Volume ON
  45. e.EmployeeId = Volume.EmployeeId
  46. END
Add Comment
Please, Sign In to add comment