• rlswisher (2/28/2012)


    For 2 and 3, I made an assumption for your field to determine if Exempt or Not, Employee State of Residence, Employee Hire Date, and Employee Birth Date

    --1.Choose a Job Description and increase by 10% all employees’ salaries that have the selected Job Description (not Job Title).

    UPDATE Employee

    SET salary = salary + (salary * (10/100))

    FROM Employee

    INNER JOIN job_title

    ON Employee.job_desc=job_title.job_desc

    WHERE job_desc = 'Obtains or prepares food items requested by customers in retail food store'

    --2. Decrease all Exempt employees’ salaries from a certain State by 15%.

    UPDATE Employee

    SET salary = salary - (salary * (15/100))

    FROM Employee

    WHERE Exempt = 'Yes' --Change this to reflect how you identify Exempt vs Non-Exempt

    And Employee_State = 'WI' --insert your state code here

    --3. Increase all Non-Exempt employees’ salaries hired more than 3 years ago that are less than 30 years of Age, by 5%.

    UPDATE Employee

    SET salary = salary + (salary * (5/100))

    FROM Employee

    WHERE Exempt = 'No' --Change this to reflect how you identify Exempt vs Non-Exempt

    And DATEDIFF(dd,Date_Hired,GETDATE()) > 1095 --365*3 = 1095, which be be the min days in 3 years, if a leap year it would be 1096.

    And (CASE WHEN (DATEADD(year,DATEDIFF(year, Birth_Date ,GETDATE()) , Birth_Date) > GETDATE())

    THEN DATEDIFF(year, Birth_Date ,GETDATE()) -1

    ELSE DATEDIFF(year, Birth_Date ,GETDATE()) END) < 30

    Or you could make the calculations a lot easier to write and understand.

    1. salary = salary * 1.1

    --I assume the description is actually in the Job title table, so you need to join on title = title.

    2. salary = salary * .85

    3. salary = salary * 1.05

    and HireDate < dateadd(yy, getdate(), -3)

    and BirthDate < dateadd(yy, getdate(), -30)

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/