Project

General

Profile

Bug #447 » alter SP.txt

untuk poin no.6 - Muhammad Bintar, 08/23/2021 02:43 PM

 
1
USE [MinovaES_Rohto_Prod]
2
GO
3
/****** Object:  StoredProcedure [dbo].[TIMECONSMD]    Script Date: 23/08/2021 12.10.56 ******/
4
SET ANSI_NULLS ON
5
GO
6
SET QUOTED_IDENTIFIER ON
7
GO
8
ALTER PROC [dbo].[TIMECONSMD]
9
 @reg_id nvarchar(MAX) ,
10
 @empid_requester nvarchar(8)
11
AS
12
BEGIN
13

    
14
DECLARE @MD NVARCHAR(100)
15
DECLARE @now NVARCHAR(8)
16
DECLARE @value NVARCHAR(100)
17
DECLARE @Time NVARCHAR(4) 
18
/*SET @reg_id ='122'*/
19
/*SET @empid_requester='00000002'*/
20
SET @now =
21
(
22
    SELECT dbo.fn_formatdatetime(GETDATE(), 'YYYYMMDD')
23
) 
24
DECLARE @DynamicSQL NVARCHAR(1000)
25
DECLARE @Table NVARCHAR(30) =
26
        (
27
            SELECT TOP (1)
28
                   TableIn
29
            FROM dbo.PCMWFDEFFIELDPOS
30
            WHERE BizFlowID =
31
            (
32
                SELECT BizflowID FROM dbo.PCMWFRUNMAIN WHERE RegID = @reg_id
33
            )
34
        )
35
SET @MD =
36
(
37
    SELECT MdSubFieldName FROM dbo.PCMEPMDCON WHERE TableName = @Table
38
)
39
SET @Time =
40
(
41
    SELECT TimeConstraint FROM dbo.PCMEPMDCON WHERE TableName = @Table
42
)
43
IF @MD <> ''
44
BEGIN
45
    SET @value =
46
    (
47
        SELECT Value
48
        FROM dbo.PCMWFRUNBIZDATA
49
        WHERE Value IN
50
              (
51
                  SELECT MdSub
52
                  FROM dbo.PCMEPMDCONSUB
53
                  WHERE TableName = @Table
54
                        AND TimeConstraint = 'N2'
55
              )
56
              AND FieldID = @MD
57
              AND RegID = @reg_id
58
              AND Sequence =
59
              (
60
                  SELECT MAX(Sequence) FROM dbo.PCMWFRUNBIZDATA WHERE RegID = @reg_id
61
              )
62
    )
63
    IF @value IS NOT NULL
64
       OR @value <> ''
65
    BEGIN
66
        SET @DynamicSQL
67
            = N'UPDATE ' + @Table + N' SET EndDate = ''' + @now + N''' WHERE EmployeeID= ''' + @empid_requester
68
              + N''' AND ' + @MD + N'=''' + @value + N''' '
69
    END
70
END
71
ELSE IF @Time = 'N2'
72
BEGIN
73
    SET @DynamicSQL
74
        = N'UPDATE ' + @Table + N' SET EndDate = ''' + @now + N''' WHERE EmployeeID= ''' + @empid_requester
75
          + N''' AND EndDate =''99991231'' '
76
END
77
EXEC (@DynamicSQL)
78
SELECT 1 AS res
79

    
80

    
81
END
(5-5/7)