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 2000 Forums
 Transact-SQL (2000)
 How to implement a modulus function in SQL 7.0

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-24 : 09:08:48
Nuvera writes "I want to divide a number lets say 25 with 6. Keeping the integer part and discarding the fraction. Usually one can do this with MOD() but so far i have not been able to find this in SQL 7.0
Any Suggesstions!!"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-06-24 : 09:10:03
Use the modulo operator % in SQL:

SELECT 25 % 6 --returns 1

Go to Top of Page

nivaskhan
Starting Member

17 Posts

Posted - 2002-06-24 : 09:54:22
you can also use FLOOR

SELECT FLOOR(25 % 6)

If u wanted it to be rounded off
u can use CEILING()


Regards,
Nivas
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-06-24 : 10:33:07
FLOOR or CEILING won't affect the modulo operation at all, there's no need to use either one of them. Also, 25 and 6 are both integers so there's nothing to round off.

Go to Top of Page

nivaskhan
Starting Member

17 Posts

Posted - 2002-06-24 : 11:31:49
"I want to divide a number lets say 25 with 6. Keeping the integer part and discarding the fraction"

Modulo will give the remainder part of the division
and not the integer part .

Since the requiment is only the Integer Part of the division
Floor() will give u the Integer Part Of the Division

SELECT FLOOR(25/6)
OR
SELECT CONVERT(INT,25/6)



Regards,
Nivas
Go to Top of Page
   

- Advertisement -