eli411
asked on
Floor function in Microsoft SQL 2008
I want to use the floor function my SQL syntax
for an example
I wanted to change the value from 95.222 to 95.125 using the Floor function. I can do it using the Excel Floor function, but I want to do the same thing in Microsoft SQL Server too.
I tried using the similar syntax but get an error message "The floor function requires 1 argument(s)
using this syntax
select (Floor(ProductCost, 0.125)) from Product
and the syntax is okay if I change to
Select (Floor(ProductCost)) from Product
anyone ever work on that before??
for an example
I wanted to change the value from 95.222 to 95.125 using the Floor function. I can do it using the Excel Floor function, but I want to do the same thing in Microsoft SQL Server too.
I tried using the similar syntax but get an error message "The floor function requires 1 argument(s)
using this syntax
select (Floor(ProductCost, 0.125)) from Product
and the syntax is okay if I change to
Select (Floor(ProductCost)) from Product
anyone ever work on that before??
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops! timing is everything!!
Declare @vVar decimal(16,5)
Declare @vSign decimal(16,5)
Set @vVar = 1234.252
Set @vSign = .125
select floor(@vVar / @vSign) * @vSign
Declare @vVar decimal(16,5)
Declare @vSign decimal(16,5)
Set @vVar = 1234.252
Set @vSign = .125
select floor(@vVar / @vSign) * @vSign
ASKER
thanks Steveo!
ASKER
95.222 will be floored to 95.125
96.9696 will be 96.875
97.7172 will be 97.625
and I tried to use the round function before but not working so well
Thanks anyway. Any other idea?