Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Applying rate increase to column value Expand / Collapse
Author
Message
Posted Friday, February 7, 2014 4:00 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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 results
Will something like this work?

SELECT
*
Salary, ROUND( (Salary * .1), 2) Percentage
FROM Employee.tbl
Post #1539428
Posted Friday, February 7, 2014 4:14 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 7:56 AM
Points: 3,941, Visits: 7,163
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

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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 Raise
FROM Employee.Tbl

Thanks for any help,
Ed
Post #1539569
Posted Sunday, February 9, 2014 9:04 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 7:56 AM
Points: 3,941, Visits: 7,163
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; 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

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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.


THX

Newb
Post #1539593
Posted Sunday, February 9, 2014 3:01 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 7:56 AM
Points: 3,941, Visits: 7,163
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
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse