Results 1 to 4 of 4

Thread: [RESOLVED] [SQL 2000] Rounding Problem

  1. #1

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Resolved [RESOLVED] [SQL 2000] Rounding Problem

    Hello,

    I have the following line in my stored procedure :
    Code:
    SET @ErrMSG = 'Employee : ' + STR(@Employee) + ' Only Has ' + STR(@AllowanceLeft) + ' days left to take.'
    When I debug through to the @AllowanceLeft part, it shows as 2.5000
    However, this message displays it as 3.

    How do I stop it rounding up please ?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [SQL 2000] Rounding Problem

    That's because you aren't specifying enough parameters to the Str function, so it applies the default behaviour, which is rounding.

    See the help for it (online version here) for more details.

  3. #3

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [SQL 2000] Rounding Problem

    Thanks Si, that's excellent.
    Apologies for not looking there first and wasting your time - I have no excuse.

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] [SQL 2000] Rounding Problem

    I am curious why you are using STR() instead of CAST().

    CAST() is much more data-aware in regard to the source datatype and the chosen destination datatype.

    CONVERT() even has more specific functionality in regard to datatype conversion.

    (I didn't even know that STR() was a SQL function )

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width