SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


NEED HELP!!! UPDATING, DELETING, ETC.


NEED HELP!!! UPDATING, DELETING, ETC.

Author
Message
spro1210
spro1210
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 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.
Steve Jones
Steve Jones
SSC Guru
SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)

Group: Administrators
Points: 150340 Visits: 19453
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
My Blog: www.voiceofthedba.com
Sean Lange
Sean Lange
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64660 Visits: 17979
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 Modens 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)
rlswisher
rlswisher
SSC-Enthusiastic
SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)

Group: General Forum Members
Points: 196 Visits: 104
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
spro1210
spro1210
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 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 :-D
Moses Smith
Moses Smith
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 181
NVM
Sean Lange
Sean Lange
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64660 Visits: 17979
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.

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)
rlswisher
rlswisher
SSC-Enthusiastic
SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)SSC-Enthusiastic (196 reputation)

Group: General Forum Members
Points: 196 Visits: 104
change the join in query 1 that I gave you to

where Employee.JobTitle = JobTitle.JobTitle

instead of joining on JobDesc
spro1210
spro1210
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 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. :-D
spro1210
spro1210
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 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! :-):-D
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search