SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 increase value by percent
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

magmo
Aged Yak Warrior

524 Posts

Posted - 01/10/2014 :  04:38:54  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 01/10/2014 :  07:41:43  Show Profile  Reply with Quote

UPDATE Table
SET Price = Price *1.05


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

magmo
Aged Yak Warrior

524 Posts

Posted - 01/10/2014 :  09:48:24  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 01/10/2014 :  09:51:09  Show Profile  Reply with Quote
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

524 Posts

Posted - 01/10/2014 :  10:23:20  Show Profile  Reply with Quote
Excellent, Thank you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/10/2014 :  23:29:41  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000