Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Script help!

Author  Topic 

barndin
Starting Member

1 Post

Posted - 2014-07-10 : 13:15:39
Example:

I have a database of employees and pay rates.
One employee has two pay rates for two different jobs:

Job A: Rate $10.00
Job B: Rate $15.00

I will be updating their record so that they only have one job going forward, Job C.
I need Job C to equal their HIGHER of the two existing jobs.

I have a select statement to find what the higher rate is.
However, I am not sure how I can apply the rate to be the new job's rate.

Here's what I used to find the highest rate for one single person:

SELECT max(rate), employeeID
FROM JobsTable
inner join IDTable
on JobsID2 = IDID2

WHERE JobCode in ('JOBA','JOBB')
and EmployeeID = '12345'
GROUP BY EmployeeID

(this returns the employee ID from one table, and the highest rate from Jobs A and B from another table)

I can get it to update to add JobC -- how can I get it to assign the result from the above query to be the rate used for Job C?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-10 : 13:24:46
http://www.sqlservercentral.com/articles/Best+Practices/61537/

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -