Money not accepted a datatype

  • I have the following:

    DECLARE BalanceDue money, ktr int

    but I get a red underline under "money" and the message I get with I put the mouse over it or run the query is:

    'money' is not a recognized CURSOR option.

    ?????

    Why is that?

    I change it to varchar and it works fine.

    Thanks,

    Tom

  • Aren't you missing the @ on your variable declaration?

    DECLARE @BalanceDue money, @ktr int

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I had just realized that after I posted it and was just going to respond to it.

    Little brain fade there.

    Thanks,

    Tom

  • Be very careful about using the money datatype. Given your variable names it sounds like you might be doing some calculations? The money datatype is NOT accurate when doing calculations. It has serious rounding errors.

    declare @mon1 money,

    @mon2 money,

    @mon3 money,

    @num1 numeric(19,4),

    @num2 numeric(19,4),

    @num3 numeric(19,4)

    select @mon1 = 100, @mon2 = 339, @mon3 = 10000,

    @num1 = 100, @num2 = 339, @num3 = 10000

    select @mon1 / @mon2 * @mon3 as MoneyType,

    @num1 / @num2 * @num3 as NumericType

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Good point.

    MoneyTypeNumericType

    2949.002949.852507

    Thanks,

    Tom

  • Sean Lange (6/7/2013)


    Be very careful about using the money datatype. Given your variable names it sounds like you might be doing some calculations? The money datatype is NOT accurate when doing calculations. It has serious rounding errors.

    declare @mon1 money,

    @mon2 money,

    @mon3 money,

    @num1 numeric(19,4),

    @num2 numeric(19,4),

    @num3 numeric(19,4)

    select @mon1 = 100, @mon2 = 339, @mon3 = 10000,

    @num1 = 100, @num2 = 339, @num3 = 10000

    select @mon1 / @mon2 * @mon3 as MoneyType,

    @num1 / @num2 * @num3 as NumericType

    +1 🙂

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 6 posts - 1 through 5 (of 5 total)

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