Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

NEED HELP!!! UPDATING, DELETING, ETC. Expand / Collapse
Author
Message
Posted Tuesday, February 28, 2012 1:25 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 5, 2012 8:51 PM
Points: 8, Visits: 9
Choose a Job Description and increase by 10% all employees’ salaries that have the selected Job Description (not Job Title).

SELECT job_title.job_desc, Employee.last_name, Employee.first_name, Employee.salary
FROM Employee
FULL JOIN job_title
ON Employee.job_desc=job_title.job_desc
UPDATE Employee
SET salary = salary + (salary * (10/100))
WHERE job_desc = ‘Obtains or prepares food items requested by customers in retail food store’

But it's not coming out right. Any ideas? One of my problems is selecting only those employees with a selected job description.

Does anybody know of where online I can go to help me with these as well?


2. Decrease all Exempt employees’ salaries from a certain State by 15%.
3. Increase all Non-Exempt employees’ salaries hired more than 3 years ago that are less than 30 years of Age, by 5%.
4. Delete any Exempt employees earning a Salary greater than a certain amount.
5. Calculate the maximum salary of all Exempt employees.
6. Calculate the sum of employee salaries for each Job Description from low to high value.
7. Calculate the minimum, maximum, and average salary for each Job_Description.

****I think I can pretty much handle 4-7 but the first 3 really have me stumped.***
The book in my class is like reading French. It's not geared to those who have very little experience in SQL. Thank you for any help you can provide.
Post #1259121
Posted Tuesday, February 28, 2012 2:05 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 9:56 AM
Points: 31,035, Visits: 15,461
An update statement doesn't have a select. It should be like:

update a
set a.column = a.column + 1
from Table1 a
inner join table2 b
on a.Col2 = b.col2









Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1259138
Posted Tuesday, February 28, 2012 2:46 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:03 AM
Points: 12,923, Visits: 12,344
spro1210 (2/28/2012)
Choose a Job Description and increase by 10% all employees’ salaries that have the selected Job Description (not Job Title).

But it's not coming out right. Any ideas?



What does that mean? Are you updating the wrong rows? Is it failing with an error message?


One of my problems is selecting only those employees with a selected job description.


Where job_desc = 'some value you want to find'


Does anybody know of where online I can go to help me with these as well?

2. Decrease all Exempt employees’ salaries from a certain State by 15%.
3. Increase all Non-Exempt employees’ salaries hired more than 3 years ago that are less than 30 years of Age, by 5%.


Yes, SSC is a good location for learning sql. Since this is obviously homework we are NOT going to spoon feed you. As you said you can handle 4-7 so for 2 and 3, what have you tried?

Keep in mind that we don't have your tables or know what columns are in them so when you post what you have tried you should also post some ddl (create table scripts) and sample data (insert statements). Take a look at the first link in my signature for best practices on posting questions.


_______________________________________________________________

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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1259161
Posted Tuesday, February 28, 2012 2:47 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 11:34 AM
Points: 134, Visits: 97
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
Post #1259162
Posted Tuesday, February 28, 2012 2:51 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 5, 2012 8:51 PM
Points: 8, Visits: 9
Thanks Steve!

I guess I was making it more complicated than it needed to be.

The only other part that I'm stuck on is I have to increase the percentage for only those employees with a certain job description BUT....

there are two tables one for job title and one for employees. The table with the job title is the one with the job description but both the job title and employee table have a job_title column. Is this where I combine the tables and use the WHERE clause? Not sure if I'm making much sense to you. But thanks anyways. lol
Post #1259165
Posted Tuesday, February 28, 2012 2:52 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 4, 2014 1:10 PM
Points: 10, Visits: 180
NVM
Post #1259167
Posted Tuesday, February 28, 2012 2:54 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:03 AM
Points: 12,923, Visits: 12,344
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1259168
Posted Tuesday, February 28, 2012 2:55 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 11:34 AM
Points: 134, Visits: 97
change the join in query 1 that I gave you to

where Employee.JobTitle = JobTitle.JobTitle

instead of joining on JobDesc
Post #1259170
Posted Tuesday, February 28, 2012 2:57 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 5, 2012 8:51 PM
Points: 8, Visits: 9
Sean,

Thanks for your help. FYI...didn't ask for any spoon feeding but I do like Vanilla ice cream. LOL.

No, just wanted a little guidance. I was stuck on the first one for some time and remembered that this was a good site to go to.

Thank you....when I go home I'm going to go through all of the responses and go from there.
Post #1259173
Posted Tuesday, February 28, 2012 3:01 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 5, 2012 8:51 PM
Points: 8, Visits: 9

rlswisher or Grasshoper (sorry still new to these forums) lol.

You read my mind. I was just going to ask you if it was going to give me an error b/c both tables do not have job_desc.

Thank you so much for your help. I really appreciate it.

Just out of curiosity. Did you learn this through a class? I'm taking an online class and it's hard when you can't get in touch with the professor for days. Do you know of any really good sources for someone not as advanced as you. I'm going to school online for my BS in IT/Database Development and really want to get good at SQL but it's not as easy I thought....at least not all of it.

Thanks again!
Post #1259175
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse