Results 1 to 7 of 7

Thread: datatype

  1. #1

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    datatype

    what datatype in sql 2000/2005 should i use for this numeric input that has two decimal value?

    ex. 1.22

    If a post has helped you then Please Rate it!

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: datatype

    How many digits to the left of the decimal point? If one, decimal (3,2).

  3. #3

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    Re: datatype

    just 2 digits (right) from the decimal point.

    ex. xxxxxx.22

    If a post has helped you then Please Rate it!

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

    Re: datatype

    We use MONEY - even though it potentially stores 4 digits to the right of the decimal point, it format's nicely to 2 digits with CONVERT() and CAST() functions.

    *** 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

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: datatype

    just 2 digits (right) from the decimal point.
    What about LEFT of the decimal point? What is the maximum value that this field can hold?

    999,999.99 - use decimal (8,2) -> 8 digits in total (Precision) with 2 decimal points (Scale)
    999,999,999.99 - use decimal (11,2) -> 11 digits in total with 2 decimal points

    The Precision determines the number of bytes SQL Server will use for this field. The two declarations above will take up 5 bytes and 9 bytes respectively. Max Precision is 38.

    Money datatypes require an explicit conversion to character datatypes, ie you must use Cast and/or Convert. Decimal datatypes are implicitly converted by sql server.
    Last edited by brucevde; Sep 7th, 2006 at 10:09 AM.

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

    Re: datatype

    We use MONEY for several reasons - not like it's important - but I thought I would mention them.

    We only use a handful of datatypes - INT, TINYINT, MONEY, DATETIME and VARCHAR().

    Based on the old keep-it-simple concept...

    MONEY links up nicely with CURRENCY in VB6 ...

    but I think that we have recently discovered that CURRENCY is no longer a datatype in VB.Net - so I see a change coming down the road...

    *** 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

  7. #7

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    Re: datatype

    thanks very informative.

    If a post has helped you then Please Rate it!

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