Project

General

Profile

Feature #1939 » Service kelipatan 5 tahun.sql

query - M Azid Wahyudi, 01/26/2023 04:07 PM

 
1
DECLARE @now VARCHAR(8) 
2
SET @now = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd')
3
DECLARE @maskerja AS TABLE (mskerja INT)
4
INSERT INTO @maskerja VALUES (5),(10),(15),(20),(25),(30),(35),(40),(45),(50),(55),(60)	
5

    
6
DECLARE @empHiring AS TABLE
7
    (
8
      EmployeeID VARCHAR(MAX) ,
9
      HiringDate VARCHAR(MAX),
10
	  [Year] VARCHAR(MAX),
11
	  [Month] VARCHAR(MAX)
12
	  --[day] VARCHAR(MAX)
13
    )
14
INSERT  INTO @empHiring
15
       SELECT EmployeeID,
16
	    HiringDate,
17
        DATEDIFF(year, HiringDate, GETDATE()) as tahun,
18
        DATEDIFF(month, HiringDate, GETDATE()) % 12 as bulan
19
        --DATEDIFF(day, HiringDate, GETDATE()) % 365 % 30 as hari
20
    FROM PHRPA0015
21

    
22
Declare @FilterHiring  AS TABLE
23
    (
24
	 StartDate VARCHAR(MAX) ,
25
      EndDate VARCHAR(MAX),
26
      EmployeeID VARCHAR(MAX) ,
27
      HiringDate VARCHAR(MAX),
28
	  [Year] VARCHAR(MAX),
29
	  [Month] VARCHAR(MAX)
30
    )
31
INSERT  INTO @FilterHiring
32
SELECT CONVERT(VARCHAR,YEAR(GETDATE()))+CONVERT(VARCHAR,SUBSTRING(@now,5,4)) StartDate ,
33
		CONVERT(VARCHAR,YEAR(GETDATE()) +5)+CONVERT(VARCHAR,SUBSTRING(@now,5,2))+ SUBSTRING(CONVERT(VARCHAR(MAX), CONVERT(DATE, DATEADD(DAY, -1, @now))),9,2) AS EndDate , * from @empHiring where  Month = '0' and SUBSTRING(HiringDate, 7, 2) = SUBSTRING(@now, 7, 2) and Year in (select * from @maskerja )
34

    
35
INSERT  INTO PHRPA0017
36
SELECT DISTINCT  StartDate AS StartDate ,
37
        EndDate AS EndDate ,
38
        EmployeeID ,
39
        '1111' AS AbsenceQuotaType ,
40
        '1' AS [Sequence] ,
41
        StartDate AS StartDeduction ,
42
        EndDate AS EndDeduction ,
43
        '5' AS OriginalQuota ,
44
        '5' AS RemainQuota ,
45
        '0' AS PreviousQuota ,
46
        EndDate AS ExpiredQuota ,
47
        'Generate Leave Quota Cuti Masa Kerja ' AS Notes,
48
		'' AS Createby,
49
		'' AS CreateDate,
50
		'' AS ChangeBy,
51
		'' AS ChangeDate
52
FROM    @FilterHiring
53

    
54

    
(3-3/3)