Project

General

Profile

Support #1819 » PDSTMTOPYVALEMPSAVEMDEXIST.sql

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

 
1
??CREATE PROCEDURE [dbo].[PDSTMTOPYVALEMPSAVEMDEXIST]
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) = '10000087'
22

23
--DECLARE @EmployeeIDEnd VARCHAR(20) = '10000087'
24

25
--DECLARE @StartDate VARCHAR(20) = '20200801'
26

27
--DECLARE @EndDate VARCHAR(20) = '20200831'
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 @Flag VARCHAR(20)
38

39
DECLARE @EmpIDRun VARCHAR(250)
40

41

42

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

45
			, @Flag = (CASE WHEN (tr800.Payroll = '1' AND tr800.TM = '') THEN 'PY' 
46

47
							WHEN (tr800.Payroll = '' AND tr800.TM <> '') THEN 'TM' 
48

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

51
						END)
52

53
FROM dbo.PHRPYTR0800 AS tr800
54

55
LEFT JOIN dbo.PHRPA0001 AS pa01
56

57
	ON pa01.EmployeeID = tr800.EmployeeID AND pa01.StartDate <= @EndDate AND pa01.EndDate >= @EndDate
58

59
WHERE (@StartDate BETWEEN tr800.StartDate AND tr800.EndDate) 
60

61
AND (tr800.EmployeeID BETWEEN @EmpIDMin AND @EmpIDMax)
62

63

64

65
SELECT ISNULL(@EmpIDRun,'') AS EmpIDRun, @Flag AS Flag
66

67

(7-7/8)