Microsoft SQL 2005 - using the modulo operator

Posted by cc0 on Stack Overflow See other posts from Stack Overflow or by cc0
Published on 2010-04-15T22:54:17Z Indexed on 2010/04/15 23:33 UTC
Read the original article Hit count: 491

Filed under:
|

So I have a silly problem, I have not used much MSSQL before, or any SQL for that matter. I basically have a minor mathematical problem that I need solved, and I thought modulo would be good.

I have a number of dates in the database, but I need them be rounded off to the closest [dynamic integer] (could be anything from 0 to 5000000) which will be input as a parameter each time this query is called.

So I thought I'd use modulo to find the remainder, then subtract that remainder from the date. If there is a better way, or an integrated function, please let me know!

What would be the syntax for that? I've tried a lot of things, but I keep getting error messages like integers/floats/decimals can't be used with the modulo operators. I tried casting to all kinds of numeric datatypes.

Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server