3 comments

  1. What about this:

    SELECT CAST(1.00/345.00 AS MONEY)
    SELECT CAST(1.00 AS MONEY)/CAST(345.00 AS MONEY)

    DataDude Beantwoorden

  2. What about:

    SELECT CAST(1.00/345.00 AS MONEY)
    SELECT CAST(1.00 AS MONEY)/CAST(345.00 AS MONEY)

    DataDude Beantwoorden

  3. My example was to clarify a problem with working with values stored as money in your database.

    The first example is therefor not relevant, as the operation works with decimals before it’s converted to money.

    The second example still truncates.

    A solution would be:

    declare @m1 money, @m2 money, @r1 decimal(19,4)
    set @m1 = 1.00;
    set @m2 = 345.00;
    set @r1 = CAST(@m1 AS DECIMAL(19,4)) / CAST(@m2 AS DECIMAL(19,4));
    SELECT @R1

    But then why not store monetary values as DECIMAL in the first place?

    robp Beantwoorden