Use ther attached case statement,inside u r query
Main Topics
Browse All TopicsI want to use a case statement to show an employee name and job title, lchange exempt employees to salaried and non-exempt employees to Hourly. also, using case statement I want to create a temporary field that calculates the total service time (in years) of each employee. In the same query, use a CASE statement to identify employees who are over 55 years old and have over 21 years of service time with the company. Identify them as Potential Retirees starting from todays date
Here is my database.
CREATE TABLE Job_title
(
[Job_ID] int PRIMARY KEY IDENTITY(1,1),
[Job_title] varchar(50) NOT NULL,
[High_wage] money NOT NULL,
[Low_wage] money NOT NULL,
[Exempt_Non_Exempt_Status]
)
GO
INSERT INTO Job_title
VALUES('Accounting Clerk',16.50,11.00,'Non-Ex
INSERT INTO Job_title
VALUES('Assistant Manager',57.00,33.00,'Exem
INSERT INTO Job_title
VALUES('Bagger',10.00,6.75
INSERT INTO Job_title
VALUES('Cashier',11.75,7.2
INSERT INTO Job_title
VALUES('Computer Support Specialist',24.50,13.75,'N
INSERT INTO Job_title
VALUES('Dir. of Fin. & Acct.',120000,50000,'Exemp
INSERT INTO Job_title
VALUES('Asst.-Bakery & Pastry',11.75,7.25,'Non-Ex
INSERT INTO Job_title
VALUES('Asst.-Butchers & Seafood Specialists',11.75,7.25,'N
INSERT INTO Job_title
VALUES('Stocker',11.75,7.2
CREATE TABLE Employee
(
[SSN] varchar(9) not null primary key,
[LastName] varchar(25) NOT NULL,
[FirstName] varchar(25) NOT NULL,
[Address] varchar(40) NOT NULL,
[City] varchar(15) NOT NULL,
[State] char(2) NOT NULL,
[Telephone_area_code] varchar(3) NOT NULL,
[Telephone_number] varchar(8) NOT NULL,
[Zipcode] varchar(5) NOT NULL,
[Job_title] varchar(50) NOT NULL,
[DateOfBirth]datetime NOT NULL,
[Hire_date] datetime NOT NULL,
[Wage] money NOT NULL,
[Job_ID] int NOT NULL REFERENCES Job_title(Job_ID)
)
GO
INSERT INTO Employee
VALUES('555555551','Edlema
'619','555-0199','92037','
INSERT INTO Employee
VALUES('555555552','McMull
'619','555-0133','91945','
INSERT INTO Employee
VALUES('555555553','Slentz
'Assistant Manager','05/26/1972','6/1
INSERT INTO Employee
VALUES('555555554','Broun'
'555-0100','92024','Bagger
INSERT INTO Employee
VALUES('555555555','Carpen
'555-0154','92024','Stocke
INSERT INTO Employee
VALUES('555555556','Esquiv
'CA','760','555-0108','920
'7/25/2003',9.25,'6');
INSERT INTO Employee
VALUES('555555557','Sharp'
'858','555-0135','92065','
INSERT INTO Employee
VALUES('555555558','Avery'
'619','555-0135','92014','
INSERT INTO Employee
VALUES('555555559','Tyink'
'858','555-0159','92014','
Select * from employee
Select * from job_title
SELECT 'FirstName', 'LastName' FROM Employee
SELECT * FROM Job_title j INNER JOIN
Employee e ON j.Job_ID = E.Job_ID
WHERE j.High_wage BETWEEN $6.00 AND $18.00
SELECT * FROM Job_title j INNER JOIN
Employee e ON j.Job_ID = E.Job_ID
WHERE e.Zipcode IN ('91945', '92024')
SELECT * FROM Job_title j INNER JOIN
Employee e ON j.Job_ID = E.Job_ID
WHERE e.Telephone_area_code LIKE '619%' OR e.Telephone_area_code LIKE '858%'
UPDATE Employee SET DateOfBirth='12/23/2009' WHERE SSN = 555555555
SELECT * FROM Employee WHERE DateDiff(Year, DateOfBirth, GetDate() ) > 40
SELECT LastName FROM Employee ORDER BY Job_title
SELECT * FROM Job_title j INNER JOIN
Employee e ON j.Job_ID = E.Job_ID
ORDER BY J.High_wage
UPDATE Employee SET Job_title='Asst. Managers' WHERE Job_title='SUPERVISORS'
SELECT * FROM Employee ORDER BY Wage DESC;
SELECT COUNT(Exempt_Non_Exempt_St
FROM Job_title
UPDATE employee
SET Wage = Wage + (Wage*2.5)
WHERE Job_title ='Assistant Manager';
UPDATE employee
SET Wage = Wage + (Wage*2.5)
WHERE Job_title ='Bagger';
UPDATE employee
SET Wage = Wage + (Wage*2.5)
WHERE Job_title ='Asst.-Bakery & Pastry';
UPDATE employee
SET Wage = Wage + (Wage*2.5)
WHERE Job_title ='Asst.-Butchers & Seafood Specialists';
UPDATE employee
SET Wage = Wage + (Wage*2.5)
WHERE Job_title ='Stocker';
SELECT * FROM Employee ORDER BY Wage DESC;
UPDATE Job_title
SET Job_title = 'Senior Director',
High_wage = 75000,
Low_wage = 65000,
Exempt_Non_Exempt_Status = 'Exempt'
WHERE Job_ID = 10
DELETE FROM Job_title
WHERE Job_title = 'Senior Director'
SELECT COUNT (Exempt_Non_Exempt_Status)
Employee e ON j.Job_title = E.Job_title
ORDER BY Job_title DESC;
SELECT j.Job_title
, j.Exempt_Non_Exempt_Status
, COUNT(*)
FROM Job_title j
JOIN Employee e
ON j.Job_title = e.Job_title
GROUP BY j.Job_title, j.Exempt_Non_Exempt_Status
ORDER BY j.Job_title DESC, j.Exempt_Non_Exempt_Status
SELECT j.Job_title
, j.Exempt_Non_Exempt_Status
, COUNT(*)
FROM Job_title j
JOIN Employee e
ON j.Job_title = e.Job_title
GROUP BY j.Job_title, j.Exempt_Non_Exempt_Status
ORDER BY j.Job_title DESC, j.Exempt_Non_Exempt_Status
SELECT MIN(Wage)- MAX(Wage) FROM Employee e join Job_title j ON
j.Job_title = e.Job_title WHERE Exempt_Non_Exempt_Status = 'Non-Exempt'
SELECT MIN(Wage)FROM Employee e join Job_title j ON
j.Job_title = e.Job_title WHERE Exempt_Non_Exempt_Status = 'Exempt'
SELECT MAX(Wage)FROM Employee e join Job_title j ON
j.Job_title = e.Job_title WHERE Exempt_Non_Exempt_Status = 'Non-Exempt'
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
That looks good, just don't forget the comma (,) between the columns and quotes (') for literal strings.
SELECT 'FirstName', 'LastName', 'Job_title' =
CASE
WHEN Exempt_Non_Exempt_Status = 'Exempt' THEN 'Salaried'
WHEN Exempt_Non_Exempt_Status = 'Non-Exempt' THEN 'Hourly'
END
FROM Employee
Seems you have picked up the case syntax from what angel eyes has instructed, but FYI for simple equals on one column most SQL systems will also accept this short hand.
SELECT 'FirstName', 'LastName'
, 'Job_title' = CASE Exempt_Non_Exempt_Status
WHEN 'Exempt' THEN 'Salaried'
WHEN 'Non-Exempt' THEN 'Hourly'
END
FROM Employee
M-1
Okay, putting it all together :
Thanks for the accepted solution, although thought others assisted you.
FYI:
If you want to show fractional years like 12.5 years, then I will usually use months and convert.
CONVERT( DECIMAL(6, 2), DATEDIFF( MONTH, Hire_date, GETDATE() ) / 12.0 ) As YearsOfService
or
CAST( DATEDIFF( MONTH, Hire_date, GETDATE() ) / 12.0 AS DECIMAL(6, 2)) As YearsOfService
Ref. to learn about CAST and CONVERT :
http://msdn.microsoft.com
Gl
Best regards and happy coding,
M-1
P.S. you can use the request attention button if you meant to close this differently and a moderator can assist you.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2009-11-03 at 03:39:27ID: 25727908
ok, learning the CASE statement starts by reading the technical reference: en-us/libr ary/ms1817 65.aspx
http://msdn.microsoft.com/
for example:
SELECT CASE WHEN DateofBirth < dateadd(year, -55, getdate()) THEN 'older than 55' ELSE '55 or less' END age_info
FROM ...