I'm a beginner with SQL queries, so any help would be greatly appreciated. I have the following select query which basically calculates the invoice amount for the client for next year depending on the number of current employees they have:
SELECT employer_plan.employer_unique, employer_plan.plan_year, employer_plan.invoice_amount, CASE WHEN COUNT(employee.employee_id)
< '6' THEN '300' WHEN COUNT(employee.employee_id) > '5' AND COUNT(employee.employee_id)
< '11' THEN '400' WHEN COUNT(employee.employee_id) > '10' AND COUNT(employee.employee_id)
< '16' THEN '500' WHEN COUNT(employee.employee_id) > '15' AND COUNT(employee.employee_id)
< '21' THEN '600' WHEN COUNT(employee.employee_id) > '20' AND COUNT(employee.employee_id)
< '51' THEN '800' WHEN COUNT(employee.employee_id) > '50' THEN '1000' END AS 'NewPrice'
FROM employer INNER JOIN
Employer_Plan ON employer.employer_unique = Employer_Plan.employer_unique INNER JOIN
employee ON employer.employer_unique = employee.employer_unique
WHERE (employee.Eligibility_Date <= GETDATE() OR
employee.Eligibility_Date IS NULL) AND (employee.Term_Date > GETDATE() OR
employee.Term_Date IS NULL) AND (Employer_Plan.plan_year = YEAR(DATEADD(month, 1,
GETDATE())))
GROUP BY employer_plan.employer_unique, employer_plan.plan_year, employer_plan.invoice_amount
The query creates a result like this:
employer_unique plan_year invoice_amount NewPrice
187671 2004 400 300
Now what I'd like to do is change this into an UPDATE query where invoice_amount will be updated with NewPrice. Like I said, I'm very new to SQl and would appreciate any help I can get with this would be great!
Thanks.
Zatch
SELECT employer_plan.employer_unique, employer_plan.plan_year, employer_plan.invoice_amount, CASE WHEN COUNT(employee.employee_id)
< '6' THEN '300' WHEN COUNT(employee.employee_id) > '5' AND COUNT(employee.employee_id)
< '11' THEN '400' WHEN COUNT(employee.employee_id) > '10' AND COUNT(employee.employee_id)
< '16' THEN '500' WHEN COUNT(employee.employee_id) > '15' AND COUNT(employee.employee_id)
< '21' THEN '600' WHEN COUNT(employee.employee_id) > '20' AND COUNT(employee.employee_id)
< '51' THEN '800' WHEN COUNT(employee.employee_id) > '50' THEN '1000' END AS 'NewPrice'
FROM employer INNER JOIN
Employer_Plan ON employer.employer_unique = Employer_Plan.employer_unique INNER JOIN
employee ON employer.employer_unique = employee.employer_unique
WHERE (employee.Eligibility_Date <= GETDATE() OR
employee.Eligibility_Date IS NULL) AND (employee.Term_Date > GETDATE() OR
employee.Term_Date IS NULL) AND (Employer_Plan.plan_year = YEAR(DATEADD(month, 1,
GETDATE())))
GROUP BY employer_plan.employer_unique, employer_plan.plan_year, employer_plan.invoice_amount
The query creates a result like this:
employer_unique plan_year invoice_amount NewPrice
187671 2004 400 300
Now what I'd like to do is change this into an UPDATE query where invoice_amount will be updated with NewPrice. Like I said, I'm very new to SQl and would appreciate any help I can get with this would be great!
Thanks.
Zatch