Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    44

    Unanswered: Decimal Datatype

    I have looked at the SQL Docs, and am trying to create a test table that uses a column of Numeric Datatype. But for some reason, it is rounding to the nearest Integer as opposed to using a decimal value.

    Heres the SQL I use to create the table:

    CREATE TABLE Test (ID int IDENTITY(1,1), Test_Numeric numeric(2,0))

    dont laugh if its obvious, cause I dont use decimal values very much :P

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Consult the Holy book (SQL Server Books online) .. here is what its says about numeric


    Numeric data types with fixed precision and scale.

    decimal[(p[, s])] and numeric[(p[, s])]

    Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The SQL-92 synonyms for decimal are dec and dec(p, s).

    p (precision)

    Specifies the maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision. The maximum precision is 38. The default precision is 18.

    s (scale)

    Specifies the maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. Scale can be specified only if precision is specified. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Ha ha ha!

    (Oops! Sorry.... )
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    You have to undersatnd what "precision" means....

    You're "0" means no positions after the decimal....the first number means the TOTAL number of digits...

    so Play with something like:

    Code:
    USE Northwind
    
    CREATE TABLE Test (ID int IDENTITY(1,1), Test_Numeric numeric(4,2))
    
    INSERT INTO TEST (Test_Numeric) SELECT 1.12
    
    SELECT * FROM Test
    
    DROP TABLE Test
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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