Results 1 to 3 of 3

Thread: [RESOLVED] Zero value cannot store in database

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] Zero value cannot store in database

    I have field name "Category" and its is number data type. Why I cannot store zero value in the table, I want to store the value like this 0001 but it store the value in the "category" field as '1' .Why?

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

    Re: Zero value cannot store in database

    0001 is a text field - we would store that as VARCHAR(4).

    Leading 0's are not supported in a numeric type of field - those fields store numbers and leading 0's, being not significant, are simply discarded.

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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Zero value cannot store in database

    In other words, if you want the leading zero's change the field type from number to text, otherwise, those zeros will continue to be dropped.

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