Skip to end of banner
Go to start of banner

Annual Active Crew notification

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

Version 1 Next »

Description

Active Crew

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

Initially intended for Havila, the task is supposed to run once a year and send a notification to Adonis informing us about a number of active crew.

Selection

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,
							'&lt;', '<'), '&gt;', '>')
							,'>bgcolor=',' bgcolor=')
          +'</table>'
Select 
@HTV as #b,
'Artem.Finkelshtein@Adonishr.com' as #email

Field Specification

Organization - Crew Pool name;

Employed Crew - number of crew employed during the last year;

Active Crew - the number of the crew who had at least one sea-service activity during the last year.

Other

  • No labels