Tuesday, August 1, 2017

Usage of math operator Modulo in SQL Server

x%y is defined as the remainder of the division x/y. You can use modulo to find the minutes and hours in so many minutes.

Let us say we have a cconversion exercise to convert 123490 minutes into minutes and hours.
By long hand we would do this:

123490/60 and find the remainder
We get 2058.1666666667 with 0.1666666667 hours converts to 10
That is 2058 hours and 10 minutes.

We can do the same using modulo as shown.


OR

You can use a much shorter code as shown here: (note input data has changed to 1234901)



No comments:

Post a Comment

What is unique to StarSQL ODBC connectivity?

 StarSQL is a database driver designed to facilitate connectivity between client applications and IBM DB2 databases. Specifically, StarSQL a...