Project

General

Profile

Bug #1630 » spGetTotalTaken.sql

GetTotalTaken - M Azid Wahyudi, 10/04/2022 12:43 PM

 
1
--ALTER PROCEDURE [dbo].[GetTotalTaken]
2
--    (
3
--      @EmployeeID VARCHAR(20),
4
--	   @StartDate VARCHAR(20),
5
--	    @EndDate VARCHAR(20)
6
--    )
7
--AS 
8

    
9
DECLARE @EmployeeID AS VARCHAR(200) ='30000134'
10
DECLARE @StartDate AS VARCHAR(200) ='20221006'
11
DECLARE @EndDate AS VARCHAR(200) ='20221006'
12

    
13
DECLARE @jumlah AS VARCHAR(200) ='0'
14
SET @jumlah = (SELECT COUNT(DAYTYP.DayType) AS jumlah FROM PHRPA0025 pa25 LEFT OUTER JOIN 
15
dbo.PHRPA0125 pa125 ON pa25.EmployeeID = pa125.EmployeeID  LEFT OUTER JOIN 
16
dbo.PHRTMDAYTYP DAYTYP ON pa125.DayType = DAYTYP.DayType AND DAYTYP.Flag='WORK'
17
WHERE pa25.EmployeeID = @EmployeeID 
18
			AND ( pa25.StartDate <= @StartDate
19
              AND pa25.EndDate >= @EndDate
20
            )
21
			AND ( pa125.EndDate BETWEEN @StartDate AND @EndDate)
22
			AND DAYTYP.DayType IS not NULL)
23
IF @jumlah = '0'
24
BEGIN
25
SET @jumlah = (SELECT COUNT(DAYTYP.DayType) AS jumlah FROM PHRPA0025 pa25 LEFT OUTER JOIN 
26
dbo.PHRTMWSCAL cal ON pa25.WorkScheduleType = cal.WorkScheduleType  LEFT OUTER JOIN 
27
dbo.PHRTMDAYTYP DAYTYP ON cal.DayType = DAYTYP.DayType AND DAYTYP.Flag='WORK'
28
WHERE pa25.EmployeeID = @EmployeeID
29
			AND ( pa25.StartDate <= @StartDate
30
              AND pa25.EndDate >= @EndDate
31
            )
32
			AND ( cal.DateSpecified BETWEEN @StartDate AND @EndDate ) 
33
			--AND cal.[Year] = YEAR(GETDATE())
34
			AND (cal.[Year]  =  YEAR(@StartDate) or cal.[Year]  =   YEAR(@EndDate))
35
		   --AND (cal.[Year]  <=  YEAR(@StartDate) and cal.[Year] >=  YEAR(@EndDate))
36
			AND DAYTYP.DayType IS not NULL)
37
end
38
SELECT @jumlah AS jumlah
(2-2/2)