Project

General

Profile

Support #1819 » PDSTMTOPYVALEMPRUNEXIS.sql

Tri Rizqiaty, 11/30/2022 05:07 PM

 
1
??--CREATE PROCEDURE [dbo].[PDSTMTOPYVALEMPRUNEXIST]
2

3
--(
4

5
--	@Variant VARCHAR(20),
6

7
--	@StartDate VARCHAR(20),
8

9
--	@EndDate VARCHAR(20),
10

11
--	@EmployeeIDStart VARCHAR(20),
12

13
--	@EmployeeIDEnd VARCHAR(20)
14

15
--)
16

17
--AS
18

19

20

21
DECLARE @EmployeeIDStart VARCHAR(20) = '06120011'
22

23
DECLARE @EmployeeIDEnd VARCHAR(20) = '06120011'
24

25
DECLARE @StartDate VARCHAR(20) = '20221001'
26

27
DECLARE @EndDate VARCHAR(20) = '20221031'
28

29
DECLARE @Variant VARCHAR(20) = '0001'
30

31

32

33
DECLARE @EmpIDMin VARCHAR(20) = CASE WHEN @EmployeeIDStart <> '' THEN @EmployeeIDStart ELSE '00000000' END
34

35
DECLARE @EmpIDMax VARCHAR(20) = CASE WHEN @EmployeeIDEnd <> '' THEN @EmployeeIDEnd ELSE '999999999' END
36

37
DECLARE @FlagPYTM VARCHAR(20)
38

39
DECLARE @Flag VARCHAR(20)
40

41
DECLARE @EmpIDRun VARCHAR(250)
42

43

44

45
SELECT TOP(1) @EmpIDRun = (tr800.EmployeeID + '-' + pa01.FullName)
46

47
			, @FlagPYTM = (CASE WHEN (tr800.Payroll = '1' AND tr800.TM = '') THEN 'PY' 
48

49
							WHEN (tr800.Payroll = '' AND tr800.TM <> '') THEN 'TM' 
50

51
							WHEN (tr800.Payroll = '1' AND tr800.TM <> '') THEN 'PYTM' 
52

53
						END)
54

55
FROM dbo.PHRPYTR0800 AS tr800
56

57
LEFT JOIN dbo.PHRPA0001 AS pa01
58

59
	ON pa01.EmployeeID = tr800.EmployeeID AND pa01.StartDate <= @EndDate AND pa01.EndDate >= @EndDate
60

61
WHERE (@StartDate BETWEEN tr800.StartDate AND tr800.EndDate)
62

63
AND tr800.Payroll = '1'
64

65
AND (tr800.EmployeeID BETWEEN @EmpIDMin AND @EmpIDMax)
66

67

68

69
IF( @FlagPYTM <> '')
70

71
BEGIN
72

73
	SELECT ISNULL(@EmpIDRun,'') AS EmpIDRun, @FlagPYTM AS Flag
74

75
END
76

77
ELSE
78

79
BEGIN
80

81
	SELECT TOP(1) @EmpIDRun = ( tr800.EmployeeID + '-' + pa01.FullName )
82

83
	FROM dbo.PHRPYTR0800 AS tr800
84

85
	LEFT JOIN dbo.PHRPA0001 AS pa01
86

87
		ON pa01.EmployeeID = tr800.EmployeeID AND pa01.StartDate <= @EndDate AND pa01.EndDate >= @EndDate
88

89
	WHERE (@StartDate BETWEEN tr800.StartDate AND tr800.EndDate) 
90

91
		AND (tr800.EmployeeID BETWEEN @EmpIDMin AND @EmpIDMax)
92

93
		AND (Variant = @Variant OR @Variant = '')
94

95
	ORDER BY tr800.EmployeeID
96

97

98

99
	SET @Flag = (CASE WHEN @EmpIDRun <> '' THEN 'Y' ELSE 'N' END)
100

101

102

103
	SELECT ISNULL(@EmpIDRun,'') AS EmpIDRun, @Flag AS Flag
104

105
END
106

107

(6-6/8)