Project

General

Profile

Bug #1038 ยป CDSWIZEXTID_20220413.sql

Tri Rizqiaty, 04/13/2022 03:59 PM

 
1
??USE [MinovaES_BankKalteng_Dev]
2

3
GO
4

5
/****** Object:  StoredProcedure [dbo].[CDSWIZEXTID]    Script Date: 13/04/2022 11.59.43 ******/
6

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15
ALTER PROCEDURE [dbo].[CDSWIZEXTID]
16
(
17
	@EmployeeID VARCHAR(20)
18
	,@HiringDate VARCHAR(20)
19
	,@BirthDate VARCHAR(20)
20
)
21
AS
22

23
--DECLARE @EmployeeID VARCHAR(20) = '10000186'
24
--DECLARE @HiringDate VARCHAR(20) = '20030101'
25
--DECLARE @BirthDate VARCHAR(20) = '19910208'
26

27
DECLARE @TahunLahir VARCHAR(20)
28
SELECT DISTINCT @TahunLahir = LEFT(PA1.BirthDate,4)
29
FROM dbo.PHRPA0001 AS PA1 
30
WHERE PA1.EmployeeID = @EmployeeID
31
	AND PA1.StartDate <= @HiringDate AND PA1.EndDate >= @HiringDate
32

33
IF(@TahunLahir  <> '') BEGIN SET @TahunLahir = @TahunLahir END ELSE SET @TahunLahir = LEFT(@BirthDate,4)
34

35
DECLARE @LastSeq VARCHAR(20)
36
SELECT DISTINCT @LastSeq = CONVERT(char, RIGHT('0000' + CONVERT(VARCHAR(4),extid.LastExtID + 1),4))
37
FROM CEXTERNALID AS extid
38
WHERE extid.[Year] = LEFT(@HiringDate,4)
39

40
IF( @LastSeq <> '')
41
BEGIN
42
	UPDATE dbo.CEXTERNALID
43
	SET LastExtID = @LastSeq
44
	WHERE [Year] = LEFT(@HiringDate,4)
45
END
46
ELSE
47
BEGIN
48
	SET @LastSeq = '0001'
49
	INSERT INTO CEXTERNALID
50
	SELECT LEFT(@HiringDate,4), @LastSeq, ''
51
END
52

53
--SELECT @TahunLahir + LEFT(@HiringDate,4) + @LastSeq AS ExternalID			////---- comment by Tri 20220413
54
SELECT @TahunLahir + SUBSTRING(@HiringDate,2,3) + @LastSeq AS ExternalID
55

56

57

    (1-1/1)