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.
Author |
Topic |
magmo
Aged Yak Warrior
558 Posts |
Posted - 2014-01-10 : 04:38:54
|
HiI 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 moneySET @Price = 1.19SELECT @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 TableSET Price = Price *1.05[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
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 |
|
|
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 thisUPDATE TableSET Price = ROUND(Price *1.05,2) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2014-01-10 : 10:23:20
|
Excellent, Thank you! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-10 : 23:29:41
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|