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)
 Rounding on Update

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2008-06-11 : 09:43:27
I need to add 3% to my prices

UPDATE prices SET price = price * 1.03

But I also need to round up to the nearest 99p so for example 1.13 becomes 1.99

How can I do this, I presume I need to round up to the nearest whole number, i.e. Math.Ceiling and then -0.01 but I dont know the syntax in SQL.

Thank you

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-11 : 09:50:36
UPDATE prices SET price = ceiling(price * 1.03) - 0.01



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-11 : 09:58:16

Would this work too?

UPDATE prices SET price = cast(price * 1.03+1 as int) - 0.01


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -