math with sql

  • When doing math with sql server, why doesn't it default to return real numbers?

    select 2621475 / 65535

    returns 40

    How do you get the remainder?

  • If you mean a true remainder, this will give it:

    select 2621475%65535

    If you actually mean you want to see the decimal fraction, this will give it:

    select 2621475./65535.

    As to why, you should read about math operations in SQL Server Books Online, but the short answer is that the code you posted is integer math and so it returns an integer result. If you want a numeric or floating point result, cast the values to that before performing the math.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply