Log in  ::  Register  ::  Not logged in

## NEED HELP!!! UPDATING, DELETING, ETC.

 Author Message spro1210 SSC-Enthusiastic Group: General Forum Members Points: 116 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.salaryFROM EmployeeFULL JOIN job_titleON Employee.job_desc=job_title.job_descUPDATE EmployeeSET 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 SSC Guru Group: Administrators Points: 332296 Visits: 20119 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: @way0utwestForum Etiquette: How to post data/code on a forum to get the best helpMy Blog: www.voiceofthedba.com Sean Lange SSC Guru Group: General Forum Members Points: 150053 Visits: 18581 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 Old Hand Group: General Forum Members Points: 301 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 EmployeeSET salary = salary + (salary * (10/100))FROM Employee INNER JOIN job_title ON Employee.job_desc=job_title.job_descWHERE 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 EmployeeSET salary = salary - (salary * (15/100))FROM Employee WHERE Exempt = 'Yes' --Change this to reflect how you identify Exempt vs Non-ExemptAnd 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 EmployeeSET salary = salary + (salary * (5/100))FROM Employee WHERE Exempt = 'No' --Change this to reflect how you identify Exempt vs Non-ExemptAnd 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 SSC-Enthusiastic Group: General Forum Members Points: 116 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 SSC Rookie Group: General Forum Members Points: 28 Visits: 181 NVM Sean Lange SSC Guru Group: General Forum Members Points: 150053 Visits: 18581 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 EmployeeSET salary = salary + (salary * (10/100))FROM Employee INNER JOIN job_title ON Employee.job_desc=job_title.job_descWHERE 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 EmployeeSET salary = salary - (salary * (15/100))FROM Employee WHERE Exempt = 'Yes' --Change this to reflect how you identify Exempt vs Non-ExemptAnd 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 EmployeeSET salary = salary + (salary * (5/100))FROM Employee WHERE Exempt = 'No' --Change this to reflect how you identify Exempt vs Non-ExemptAnd 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) < 30Or 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 * .853. salary = salary * 1.05and 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 Old Hand Group: General Forum Members Points: 301 Visits: 104 change the join in query 1 that I gave you towhere Employee.JobTitle = JobTitle.JobTitleinstead of joining on JobDesc spro1210 SSC-Enthusiastic Group: General Forum Members Points: 116 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 SSC-Enthusiastic Group: General Forum Members Points: 116 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

## 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
 SQL Server 2017      SQL Server 2017 - Administration      SQL Server 2017 - Development SQL Server 2016      SQL Server 2016 - Administration      SQL Server 2016 - Development and T-SQL SQL Server 2014      Administration - SQL Server 2014      Development - SQL Server 2014 SQL Server 2012      SQL 2012 - General      SQL Server 2012 - T-SQL SQL Server vNext      SQL Server 15 - Administration      SQL Server 15 - Development SQL Server 2008      SQL Server 2008 - General      T-SQL (SS2K8)      June 2007 CTP      Working with Oracle      July CTP      SQL Server Newbies      Security (SS2K8)      SQL Server 2008 High Availability      SQL Server 2008 Administration      Data Corruption (SS2K8 / SS2K8 R2)      SQL Server 2008 Performance Tuning Cloud Computing      SQL Azure - Development      SQL Azure - Administration      Amazon AWS and other cloud vendors      General Cloud Computing Questions      CosmosDB      Azure Data Lake      Azure Machine Learning Reporting Services      Reporting Services      Reporting Services 2005 Administration      Reporting Services 2005 Development      Reporting Services 2008/R2 Administration      Reporting Services 2008 Development      SSRS 2012      SSRS 2014      SSRS 2016 Programming      Connecting      General      SMO/RMO/DMO      XML      Service Broker      Powershell      Testing      TFS/Data Dude/DBPro      SSDT      Continuous Integration, Deployment, and Delivery      R Services and R Language Data Warehousing      Integration Services      Strategies and Ideas      Analysis Services      Data Transformation Services (DTS)      Performance Point      Data Mining      PowerPivot      R language      Machine Learning Database Design      Disaster Recovery      Design Ideas and Questions      Relational Theory      Hardware      Virtualization      Security and Auditing SQLServerCentral.com      Anything that is NOT about SQL!      Contests!      Editorials      SQLServerCentral.com Announcements      SQLServerCentral.com Website Issues      Suggestions      Tag Issues with Content      Podcast Feedback      SQLServerCentral.com Test Forum      Articles Requested SQL Server 2005      Administering      Backups      Business Intelligence      CLR Integration and Programming.      Data Corruption      Development      Working with Oracle      SQL Server 2005 Compact Edition      SQL Server 2005 General Discussion      SQL Server 2005 Security      SQL Server 2005 Strategies      SS2K5 Replication      SQL Server Express      SQL Server 2005 Performance Tuning      SQL Server 2005 Integration Services      T-SQL (SS2K5)      SQL Server Newbies SQL Server 7,2000      Administration      Backups      Data Corruption      General      Globalization      In The Enterprise      Working with Oracle      Security      Strategies      SQL Server Newbies      Service Packs      SQL Server CE      Performance Tuning      Replication      Sarbanes-Oxley      T-SQL      SQL Server Agent SQL Server and other platforms      MySQL      Oracle      PostgreSQL      DB2      SQL Server and Sharepoint Older Versions of SQL (v6.5, v6.0, v4.2)      Older Versions of SQL (v6.5, v6.0, v4.2) Career      Certification      Employers and Employees      Events      Job Postings      Resumes and Job Hunters      Presentations and Speaking      Retired Members Testing Center      SQL Server Security Skills      Question of the Day (QOD) Microsoft Access      Microsoft Access Products and Books      Third Party Products         SQLCentric         Extreme Technologies.         Innovartis         Embarcadero         SQL Sentry         Sonasoft         Golden Gate Software         Idera         Lumigent         Red Gate Software         ApexSQL         Quest Software         CA      Discussions about Books         Discuss Programming Books          Discuss XML Books          Discuss T-SQL Books          Discuss Data Warehousing Books          Discuss DTS Books          Discuss SQL Server 2000 Books         Discuss SQL Server 7.0 Books Notification Services      Administration Article Discussions Future Versions      SQL 12

## Search

 Copyright © 2002-2018 Redgate. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.