Project

General

Profile

Bug #930 » CNAF_bitype.sql

Mr. Yusuf, 03/18/2022 07:40 AM

 
1
/*
2
DECLARE @landscape AS VARCHAR(50) = '100'
3
DECLARE @now8 AS VARCHAR(50) = '20220101'
4
DECLARE @object_from AS VARCHAR(50) = '00000004'
5
DECLARE @object_to AS VARCHAR(50) = '00000004'
6
*/
7
DECLARE @last_success AS VARCHAR(14) = '20111001000000' 
8
SELECT @last_success = format(DATEADD(month, -1, getdate()),'yyyyMMddHHmmss')
9

    
10
SELECT 
11
  TOP (1) @last_success = dt.run_at 
12
FROM 
13
  dbo.svc_log_detail AS dt 
14
WHERE 
15
  dt.landscape = @landscape 
16
  AND dt.svc_type = 'EMP_OM_RECAP' 
17
  AND dt.[status] = 'S' 
18
ORDER BY 
19
  dt.run_at DESC 
20

    
21
DECLARE @emptable AS TABLE (
22
    empID VARCHAR(20), 
23
    posID VARCHAR(20), 
24
    orgID VARCHAR(20), 
25
    last_change VARCHAR(20)
26
  )
27
INSERT INTO @emptable 
28
SELECT 
29
  md2.emp_id, 
30
  md2.position, 
31
  organization,
32
  last_change
33
FROM 
34
  dbo.hr_md_emp_md0002 AS md2 
35
WHERE 
36
  md2.landscape = @landscape 
37
  AND md2.start_date <= @now8 
38
  AND md2.end_date >= @now8 
39
  AND md2.last_change >= @last_success 
40
  AND (
41
    (
42
      @object_from <> '' 
43
      AND @object_to <> '' 
44
      AND md2.emp_id >= @object_from 
45
      AND md2.emp_id <= @object_to
46
    ) 
47
    OR (
48
      @object_from = '' 
49
      AND @object_to = ''
50
    )
51
  )
52

    
53
DECLARE @tableOrgID AS TABLE (
54
    id INT IDENTITY, 
55
    org VARCHAR(20)
56
  )
57

    
58
INSERT INTO @tableOrgID 
59
SELECT 
60
  rel_object 
61
FROM 
62
  dbo.hr_md_orm_relationship AS rel, 
63
  @emptable tb1 
64
WHERE 
65
  rel.class = 'P' 
66
  AND rel.rel_class = 'O' 
67
  AND rel.object = tb1.posID 
68
  AND rel.rel_type = '002' 
69
  AND rel.start_date <= @now8 
70
  AND rel.end_date >= @now8
71
DECLARE @i AS INT = 1
72
DECLARE @countOrg AS INT = 0 
73
SELECT 
74
  @countOrg = COUNT(*) 
75
FROM 
76
  @tableOrgID
77

    
78
WHILE (@i <= @countOrg)
79
BEGIN 
80
	DECLARE @org_nya AS VARCHAR(8) 
81
	SELECT 
82
	  @org_nya = org 
83
	FROM 
84
	  @tableOrgID 
85
	WHERE 
86
	  id = @i
87
	
88
	INSERT INTO @emptable (empID) 
89
	SELECT 
90
	  emp_id 
91
	FROM 
92
	  dbo.hr_md_emp_md0002 AS md2 
93
	  INNER JOIN (
94
		SELECT 
95
		  DISTINCT rel_obj 
96
		FROM 
97
		  dbo.GetObjectChildAll(
98
			'100', @org_nya, 'O', 'O', '99991231'
99
		  )
100
	  ) AS ls ON md2.organization = ls.rel_obj 
101
	WHERE 
102
	  md2.landscape = @landscape 
103
	  AND md2.start_date <= @now8 
104
	  AND md2.end_date >= @now8 
105

    
106
	SET 
107
	  @i = @i + 1
108
END
109

    
110
SELECT 
111
  DISTINCT empID 
112
FROM 
113
  @emptable
(2-2/2)