Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 increase value by percent

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-01-10 : 04:38:54
Hi

I have the need to update a bunch of values in a table and the column data type is "Money", the value should be increased with 5% and make the correct rounding. I tried this, but thats not right...



DECLARE @Price money
SET @Price = 1.19
SELECT @Price * 1.04
--PRINT ROUND(@Price,2)
PRINT CONVERT(DECIMAL(7,2), @Price)



Can anyone help?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-10 : 07:41:43
[code]
UPDATE Table
SET Price = Price *1.05
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-01-10 : 09:48:24
Sorry, in my code it should of course have been * 1.05 but to only use the suggested code give 1.249500 which isnt right. It should round correct and be like this 1.25
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-10 : 09:51:09
quote:
Originally posted by magmo

Sorry, in my code it should of course have been * 1.05 but to only use the suggested code give 1.249500 which isnt right. It should round correct and be like this 1.25


if your datatype is money it will have scale value of 4 (upto 4 decimal places). so if you want to round upto 2 decimal places you can use this


UPDATE Table
SET Price = ROUND(Price *1.05,2)





------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-01-10 : 10:23:20
Excellent, Thank you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-10 : 23:29:41
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -