Академический Документы
Профессиональный Документы
Культура Документы
crpt_ComPsychFMLA_36945'))
GO
/*
Date: 6/29/2018
Example:
Drop all temporary table objects that exist in the tempDB for the current session
*/
@UserID VARCHAR(50),
@std_FilterValue XML
AS
SET NOCOUNT ON
--Update the parameter string to include the P11 date range for the previous 12 months
--EInfo
SELECT
eInfoID,
co,
id,
lastName,
firstName,
middleName,
address1,
address2,
city,
state,
zip,
county,
country,
workAddress1,
workAddress2,
workCity,
workState,
workZip,
workCounty,
workCountry,
phone1,
phone1Type,
phone1Ext,
ssn,
birthDate,
sex,
empStatus,
empType,
rehireDate,
adjSeniorityDate,
termDate,
positionCode,
title,
emailAddress,
personalEmail,
cCostCenterMatrixID,
salary,
defaultHours,
annualSalary,
rateCode,
hireDate,
otExempt
--cCostCenterMatrix
SELECT
cCostCenterMatrixID,
co,
cc1,
cc2,
cc3,
cc4,
cc5,
cc1name,
cc2name,
cc3name,
cc4name,
cc5name
--CInfo
SELECT
cInfoID,
co,
name
INTO #CInfo
Into #CompanyCustomFields
From report.CUserDefinedFields_tfn(@UserID,@std_FilterValue) f
Join escher.CUserDefinedFieldValues
v With (NoLock) on v.CUserDefinedFieldID = f.CUserDefinedFieldID
SELECT
gd.co,
gd.detType AS det,
gd.detcode,
g.codegroup
INTO #CodeGroup
gd.cCodeGroupID = g.cCodeGroupID
c.co = g.co
SELECT
ePayHistID,
co,
id,
checkDate,
process
--EPayHistDetail
SELECT
ePayHistDetailID,
ePayHistID,
co,
id,
det,
detCode,
hours
SELECT
eph.co,
eph.id,
SUM(ephd.hours) AS Prev12MonthHours
INTO #Previous12MonthHours
eph.ePayHistID = ephd.ePayHistID
cg.detcode = ephd.detcode
GROUP BY
eph.co,
eph.id
--Benefit Class
SELECT
b.eBenefitsSetupID,
b.co,
b.id,
b.categoryEffectiveDate,
b.class,
INTO #EBenefitsSetup
ei.id = b.id
WHERE categoryEffectiveDate <= GETDATE()
--Final select
SELECT
ci.co,
ccf.fieldValue AS AccountNumber,
ci.name AccountName,
ei.id AS EmployeeID,
ei.ssn AS EmployeeSSN,
REPLACE(ei.firstname,',','') AS FirstName,
LEFT(LTRIM(RTRIM(ei.middlename)), 1) AS middlename,
REPLACE(ei.lastname,',','') AS LastName,
REPLACE(ei.address1,',','') AS HomeAddressLine1,
REPLACE(ei.address2,',','') AS HomeAddressLine2,
REPLACE(ei.city,',','') AS HomeCity,
ei.state AS HomeState,
SUBSTRING(ei.zip,1,5) AS HomeZip,
ei.phone1 AS HomePhone,
ei.sex AS Gender,
ei.birthDate AS DateOfBirth,
'' AS PrimaryLanguage,
'' AS WorkAddressID,
'' AS WorkAddressLine1,
'' AS WorkAddressLine2,
REPLACE(ei.city,',','') AS WorkCity,
ei.state AS WorkState,
SUBSTRING(ei.workZip,1,5) AS WorkZip,
'USA' AS WorkCountry,
'' AS WorkPhone,
'' AS WorkPhoneExtension,
ccm.cc1 AS BusinessUnit,
ci.co AS Organization,
b.class AS EmployeeGroup1,
'' AS EmployeeGroup2,
'' AS EmployeeGroup3,
'' AS EmployeeGroup4,
'' AS EmployeeGroup5,
'' AS EmployeeGroup6,
'' AS EmployeeGroup7,
'' AS EmployeeGroup8,
CASE WHEN ei.empType = 'RFT' THEN 'F' ELSE 'P' END AS FullTimePartTimeStatus,
CONVERT(varchar,ei.hireDate,110) AS HireDate,
CONVERT(varchar,ei.rehireDate,110) AS AdjustedEmploymentDate,
'' AS AnniversaryDate,
CONVERT(varchar,ei.termDate,110) AS TerminationDate,
prev.Prev12MonthHours AS Prev12MonthHours,
'' AS KeyEmployee,
REPLACE(ei.positionCode,',','') AS JobTitle,
ei.emailAddress AS WorkEmail,
ei.defaultHours AS ScheduledHours,
'5' AS ScheduledDaysPerWeek,
'' AS AdditionalLetterRecipientEmail,
'' AS SpouseEmployed,
'' AS SpouseEmployeeID,
'' AS PrimaryContactID,
ei.annualSalary AS STDEarnings,
CONVERT(varchar,b.categoryEffectiveDate,110) AS STDEligibilityDate,
CONVERT(varchar,b.categoryEffectiveDate,110) AS LTDEligibilityDate,
'' AS EmployerContact2IDS,
'' AS EmployerContact3IDS,
'' AS EmployerContact4IDS,
'' AS EmployerContact5IDS,
'' AS EmployerContact6IDS,
'' AS EmployerContact7IDS,
'' AS EmployerContact8IDS,
'' AS EmployerContact9IDS,
'' AS EmployerContact10IDS
FROM #EInfo ei
ci.co = ei.co
ccm.cCostCenterMatrixID = ei.cCostCenterMatrixID
b.id = ei.id
ccf.co=ci.co