Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Applying rate increase to column value Rate Topic Display Mode Topic Options
Author
 Message
 Posted Friday, February 7, 2014 4:00 PM
 Forum Newbie Group: General Forum Members Last Login: Sunday, February 9, 2014 2:54 PM Points: 3, Visits: 5
 I need to take salary and add a 10 percent increase to it and display the resultsWill something like this work?SELECT *Salary, ROUND( (Salary * .1), 2) PercentageFROM Employee.tbl
Post #1539428
 Posted Friday, February 7, 2014 4:14 PM
 SSCarpal Tunnel Group: General Forum Members Last Login: 2 days ago @ 7:01 AM Points: 4,792, Visits: 7,356
 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; They'll drag you down to their level and beat you with experience"
Post #1539430
 Posted Sunday, February 9, 2014 8:44 AM
 Forum Newbie Group: General Forum Members Last Login: Sunday, February 9, 2014 2:54 PM Points: 3, Visits: 5
 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 RaiseFROM Employee.TblThanks for any help,Ed
Post #1539569
 Posted Sunday, February 9, 2014 9:04 AM
 SSCarpal Tunnel Group: General Forum Members Last Login: 2 days ago @ 7:01 AM Points: 4,792, Visits: 7,356
 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 RaiseFROM @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 RaiseFROM @Employee` ______________________________________________________________________________"Never argue with an idiot; They'll drag you down to their level and beat you with experience"
Post #1539570
 Posted Sunday, February 9, 2014 2:41 PM
 Forum Newbie Group: General Forum Members Last Login: Sunday, February 9, 2014 2:54 PM Points: 3, Visits: 5
 Thanks....Works like a charm.Luck Bastard got his raise.THXNewb
Post #1539593
 Posted Sunday, February 9, 2014 3:01 PM
 SSCarpal Tunnel Group: General Forum Members Last Login: 2 days ago @ 7:01 AM Points: 4,792, Visits: 7,356
 Awesome, he'll be very happy on Monday ______________________________________________________________________________"Never argue with an idiot; They'll drag you down to their level and beat you with experience"
Post #1539596

 Permissions