...
Description
...
Table of Contents |
---|
minLevel | 1 |
---|
maxLevel | 1 |
---|
type | flat |
---|
separator | pipe |
---|
|
Page Properties |
---|
Summary | Displays the number of crew active during the last year |
---|
Keywords | File / Script Link |
---|
Compatibility APM Version | N/A |
---|
Compatibility SQL Version | 2008R2 or higher |
---|
|
Description
...
Description
The task is supposed to run once a year and send a notification to Adonis the Personnel Manager informing us about a the number of active crew.
...
SQL Statement
Expand |
---|
|
Code Block |
---|
| declare @HTV varchar(max);
set @HTV = cast(
(select td = Convert(varchar(40),d.Org)
+'</td><td>' + Isnull(Convert(varchar,d.Employed),'')
+'</td><td>' + Isnull(Convert(varchar,d.ActEmployees),'')
from (select o.[NAME] Org,
(Select Count(PIN) From (
Select X.PIN From
(Select a.PIN From AUDIT_PW001P01 a
where dbo.ad_IsClient(a.CLIENT,o.NUMORGID)=1 and a.repl_GMTModifiEDDate>=DATEADD(year,-1,getdate())
and a.EMPLOYMENTSTARTDATE is not null and (a.EMPLOYMENTENDDATE is null or a.EMPLOYMENTENDDATE>a.repl_ModifiedDate)
Union all
Select p.PIN From PW001P01 p
where dbo.ad_IsClient(p.CLIENT,o.NUMORGID)=1
and p.EMPLOYMENTSTARTDATE is not null and (p.EMPLOYMENTENDDATE is null or p.EMPLOYMENTENDDATE>DATEADD(year,-1,getdate()))
) X
Group by x.PIN) Y) Employed,
(Select Count(PIN) From (
Select PIN From PW001P03 Where Code in (Select CODE From PW001C12 Where OPTIONS like '%S%')
and Convert(date,DATEFROM)<=Convert(date,getdate())
and Convert(date,Isnull(Isnull(DATETO,TODATEESTIMATED),Getdate()))>=Convert(date,dateadd(year,-1,getdate()))
and PLANNED!='Y'
and PIN in (Select PIN From AUDIT_PW001P01 where dbo.ad_IsClient(CLIENT,o.NUMORGID)=1)
Group by PIN) Y) ActEmployees
from pworg o
where o.orgtype=2 and o.[NAME] like '%crew%pool%'
) as d
order by d.Org asc
for xml path( 'tr' ), type)
as varchar(max) )
set @HTV = '<table cellpadding="3" cellspacing="0" border="1">'
+'<tr><th>Organization</th><th>Employed Crew</th><th>Active Crew</th></tr>'
+Replace(Replace(Replace(@HTV,
'<', '<'), '>', '>')
,'>bgcolor=',' bgcolor=')
+'</table>'
Select
@HTV as #b,
'Artem.Finkelshtein@Adonishr.com' as #email
|
|
Field Specification
Organization - Crew Pool name;
...
Active Crew - the number of the crew who had at least one sea-service activity during the last year.
...