SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Applying rate increase to column value


Applying rate increase to column value

Author
Message
edppalms
edppalms
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
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
MyDoggieJessie
MyDoggieJessie
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12454 Visits: 7444
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" ;-)
edppalms
edppalms
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
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
MyDoggieJessie
MyDoggieJessie
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12454 Visits: 7444
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" ;-)
edppalms
edppalms
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 5
Thanks....Works like a charm.

Luck Bastard got his raise.


THX

Newb
MyDoggieJessie
MyDoggieJessie
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12454 Visits: 7444
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" ;-)
Go


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

































































































































































SQLServerCentral


Search