1
|
DECLARE @StartDate VARCHAR(12) = '20240101'
|
2
|
DECLARE @EndDate VARCHAR(12) = '20240808'
|
3
|
DECLARE @Position VARCHAR(12) = ''
|
4
|
DECLARE @ApplicantIDTo VARCHAR(12) = ''
|
5
|
DECLARE @ApplicantIDFrom VARCHAR(12) = ''
|
6
|
DECLARE @ApplicantActivity VARCHAR(12) = ''
|
7
|
DECLARE @ApplicantStatus VARCHAR(12) = ''
|
8
|
DECLARE @MenuID VARCHAR(10) = 'PA01'
|
9
|
DECLARE @Userid VARCHAR(10) = 'minovais'
|
10
|
|
11
|
|
12
|
DECLARE @table_maxtivity AS TABLE ( emp_id VARCHAR(18) )
|
13
|
|
14
|
|
15
|
|
16
|
|
17
|
INSERT INTO @table_maxtivity
|
18
|
SELECT EmployeeID
|
19
|
FROM dbo.PHRRC0027
|
20
|
GROUP BY EmployeeID
|
21
|
|
22
|
--select * from @table_maxtivity
|
23
|
|
24
|
--INSERT INTO @table_activity
|
25
|
SELECT m2.Position ,
|
26
|
pb.ObjectDescription Positiondesc ,
|
27
|
m1.EmployeeID ,
|
28
|
m1.FullName ,
|
29
|
m1.BirthPlace ,
|
30
|
m1.BirthDate ,
|
31
|
gend.GenderDescription gender ,
|
32
|
marstat.MaritalStatusDescription marital ,
|
33
|
edulvl.EducationLevelDescription edulevel ,
|
34
|
m8.Institution ,
|
35
|
FORMAT(m8.GPA,'N2') AS GPA,
|
36
|
m2.ApplicantAction,
|
37
|
act.ApplicantActionDescription ,
|
38
|
m2.ApplicantStatus ,
|
39
|
stat.ApplicantStatusDescription AS AppActDes ,
|
40
|
CONVERT(VARCHAR(25), dbo.fn_formatdatetime(@StartDate, 'dd mmmm yyyy')) AS StartDate ,
|
41
|
CONVERT(VARCHAR(25), dbo.fn_formatdatetime(@EndDate, 'dd mmmm yyyy')) AS EndDate
|
42
|
FROM dbo.PHRRC0001 m1
|
43
|
LEFT OUTER JOIN dbo.PHRRC0002 m2 ON m1.EmployeeID = m2.EmployeeID
|
44
|
AND m2.StartDate <= @EndDate
|
45
|
AND m2.EndDate >= @StartDate
|
46
|
LEFT OUTER JOIN dbo.PHRRC0008 m8 ON m1.EmployeeID = m8.EmployeeID
|
47
|
AND m8.StartDate <= @EndDate
|
48
|
AND m8.EndDate >= @StartDate
|
49
|
LEFT OUTER JOIN dbo.PHRRC0009 AS m9 ON m9.EmployeeID = m1.EmployeeID
|
50
|
AND m9.StartDate <= @EndDate
|
51
|
AND m9.EndDate >= @StartDate
|
52
|
LEFT OUTER JOIN dbo.PHRRCAPPSTAT stat ON m2.ApplicantStatus = stat.ApplicantStatus
|
53
|
AND stat.StartDate <= @EndDate
|
54
|
AND stat.EndDate >= @StartDate
|
55
|
LEFT OUTER JOIN dbo.PHRRCAPPACT act ON m2.ApplicantAction = act.ApplicantAction
|
56
|
AND act.StartDate <= @EndDate
|
57
|
AND act.EndDate >= @StartDate
|
58
|
LEFT OUTER JOIN dbo.PHRPAGENDER gend ON m1.Gender = gend.Gender
|
59
|
LEFT OUTER JOIN dbo.PHRPAMSTAT marstat ON m1.MaritalStatus = marstat.MaritalStatus
|
60
|
LEFT OUTER JOIN dbo.PHRPAEDULVL edulvl ON m8.EducationLevel = edulvl.EducationLevel
|
61
|
LEFT OUTER JOIN dbo.PHROM0001 jb ON m2.Job = jb.ObjectID
|
62
|
AND jb.ObjectClass = 'J'
|
63
|
LEFT OUTER JOIN dbo.PHROM0001 pb ON m2.Position = pb.ObjectID
|
64
|
AND pb.ObjectClass = 'P'
|
65
|
INNER JOIN @table_maxtivity maxtivity ON maxtivity.emp_id = m2.EmployeeID
|
66
|
WHERE m2.StartDate <= @EndDate
|
67
|
AND ( m1.EndDate >= @StartDate )
|
68
|
AND ( m1.EmployeeID >= @ApplicantIDFrom
|
69
|
OR @ApplicantIDFrom = ''
|
70
|
)
|
71
|
AND ( m1.EmployeeID <= @ApplicantIDTo
|
72
|
OR @ApplicantIDTo = ''
|
73
|
)
|
74
|
AND ( m2.Position = @Position
|
75
|
OR @Position = ''
|
76
|
)
|
77
|
AND ( m2.ApplicantAction= @ApplicantActivity
|
78
|
OR @ApplicantActivity = ''
|
79
|
)
|
80
|
AND ( m2.ApplicantStatus = @ApplicantStatus
|
81
|
OR @ApplicantStatus = ''
|
82
|
)
|