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

SQL Server 2025 ready to go

 I have not yet done looking at SQL Server 2022, SQL Server 2025 is ready to go. Microsoft is indeed relentless!  Microsoft announced SQL Se...