Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case problem

Status
Not open for further replies.

Deam

Programmer
Oct 10, 2000
68
US
I need to Update the _PersonTemp table with AnnualSalaries. The annual salary calc is different for some emps. So I have to take both kinds into consideration. But my update Annual Salary works only one at a time. How can I combine the calcs.( the Update annual Salary part are further down, there is a comment as
--Problem section-->


Please help.

Drop Table _PersonTemp
GO

Declare @BenefitPlanCode shrsCode,
@BenefitOption shrsCode ,
@EffectiveDate datetime

Select @BenefitPlanCode = 'SP'
Select @BenefitOption = '1'
Select @EffectiveDate = GETDATE()
SET NOCOUNT ON

-- Declare internal variables
DECLARE @YearCode shrsCode
SELECT @YearCode = 'YR'

-- Create temporary table to store spouse information (age as of 12/31)
CREATE TABLE _PersonTemp
(PersonGUID uniqueidentifier NOT NULL,
BenefitPlanCode varchar(15) NOT NULL,
BenefitOption varchar(15) NOT NULL,
SpouseGUID uniqueidentifier NULL,
SpouseBirthDate datetime NULL,
SpouseAge integer NULL,
AnnualSalary money NULL)

-- Populate the temporary table with all of the PersonGUIDs from UBC
INSERT INTO _PersonTemp (PersonGUID, BenefitPlanCode, BenefitOption, SpouseGUID, SpouseBirthDate)
SELECT DISTINCT
u.PersonGUID, u.BenefitPlanCode, u.BenefitOption,
d.DependenEmployeeGUID, p.BirthDate
FROM UBC u INNER JOIN
EmployeeDependent d ON
d.PersonGUID = u.PersonGUID INNER JOIN
Employeeal p ON
d.DependenEmployeeGUID = p.PersonGUID INNER JOIN
EmployeeBenefitHist b ON b.PersonGUID = u.PersonGUID AND
b.BenefitPlanCode = u.BenefitPlanCode AND
b.BenefitOption = u.BenefitOption INNER JOIN
EmployeeBenefitHist b1 ON
b1.PersonGUID = d.DependenEmployeeGUID
WHERE (u.BenefitPlanCode = @BenefitPlanCode
AND (u.BenefitOption = @BenefitOption OR @BenefitOption IS NULL))
AND (d.RelationshipCode = 'HU' OR d.RelationshipCode = 'WI')
AND (@EffectiveDate BETWEEN b.PersonBenefitStartDate AND ISNULL(b.PersonBenefitEndDate, CONVERT(DATETIME, '99991231')))
AND --(p.PersonGUID = '26C5CB71-1834-11D5-8777-000000000000') AND u.UserName = SUSER_SNAME()
-- Calculate Annual Base Salary

--Problem section-->
UPDATE _PersonTemp
SET AnnualSalary = (p.PlannedAmount * f.ConversionFactor)
-- Calculate Annual Targeted Earnings
FROM (_PersonTemp t
INNER JOIN EmployeeOPHist p
ON t.PersonGUID = p.PersonGUID)
INNER JOIN EmployeeJobHist j
ON j.PersonGUID = p.PersonGUID
INNER JOIN tJob jb
ON j.JobCode = jb.JobCode,
tFrequencyConversion f
WHERE @EffectiveDate BETWEEN p.PersonOPStartDate
AND ISNULL(p.PersonOPEndDate, CONVERT(DATETIME, '99991231'))
AND @EffectiveDate BETWEEN j.PersonJobStartDate
AND ISNULL(j.PersonJobEndDate, CONVERT(DATETIME, '99991231'))
AND f.FromFrequencyCode = p.PlannedFrequencyCode
AND f.ScheduleCode = j.ScheduleCode
AND f.ToFrequencyCode = @YearCode
AND OPTypeCode = 'COMM'
AND(jb.JobGroupCode = 'AE' OR jb.AlternateJobCode = 'AE')
UPDATE _PersonTemp
SET AnnualSalary =
-- Calculate Annual Base Salary
(p.PersonBPAmount * f.ConversionFactor)
FROM (_PersonTemp t
INNER JOIN EmployeeBPHist p
ON t.PersonGUID = p.PersonGUID)
INNER JOIN EmployeeJobHist j
ON j.PersonGUID = p.PersonGUID
INNER JOIN tJob jb
ON j.JobCode = jb.JobCode,
tFrequencyConversion f
WHERE @EffectiveDate BETWEEN p.PersonBPStartDate
AND ISNULL(p.PersonBPEndDate, CONVERT(DATETIME, '99991231'))
AND @EffectiveDate BETWEEN j.PersonJobStartDate
AND ISNULL(j.PersonJobEndDate, CONVERT(DATETIME, '99991231'))
AND f.FromFrequencyCode = p.PersonBPFrequencyCode
AND f.ScheduleCode = j.ScheduleCode
AND f.ToFrequencyCode = @YearCode
AND (jb.JobGroupCode != 'AE' OR jb.AlternateJobCode != 'AE')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top