February 7, 2014 at 4:00 pm
I need to take salary and add a 10 percent increase to it and display the results
Will something like this work?
SELECT
*
Salary, ROUND( (Salary * .1), 2) Percentage
FROM Employee.tbl
February 7, 2014 at 4:14 pm
Yep, or you can add it to the base amount like so:
SELECT 58261.21, ROUND((58261.21 * .1), 2), ROUND((58261.21 * 1.1), 2)
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
February 9, 2014 at 8:44 am
I keep getting MSG 102 Syntax error Near 'salary'. I am trying to calculate a 10 percent raise based on salary from the Employee table.
SELECT
*
Salary, ROUND( (Salary * .1), 2) AS Raise
FROM Employee.Tbl
Thanks for any help,
Ed
February 9, 2014 at 9:04 am
You can't alias the "*"
You need a comma after the star, like so: DECLARE @Employee TABLE (FullName varchar(10), Salary money)
INSERT INTO @Employee
SELECT 'John Doe', 85000 UNION ALL
SELECT 'Jane Doe', 87244 UNION ALL
SELECT 'John Doe', 77854 UNION ALL
SELECT 'John Doe', 94875
SELECT
*, ROUND( (Salary * .1), 2) AS Raise
FROM @Employee You should always write out the columns names wherever possible and refrain from using "*" when possible.
Ex:DECLARE @Employee TABLE (FullName varchar(50), Salary money)
INSERT INTO @Employee
SELECT 'John Doe', 85000 UNION ALL
SELECT 'Jane Doe', 87244 UNION ALL
SELECT 'Tim McGraw', 77854 UNION ALL
SELECT 'Arnold Stumph', 94875
SELECT
FullName [LuckyBa$tard], Salary, ROUND( (Salary * .1), 2) AS Raise
FROM @Employee
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
February 9, 2014 at 2:41 pm
Thanks....Works like a charm.
Luck Bastard got his raise.
THX
Newb
February 9, 2014 at 3:01 pm
Awesome, he'll be very happy on Monday 🙂
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply