Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Mar 2004
    Posts
    74

    Unanswered: Why '1' or '0' is not accept in bit datatype ?

    Hi All,

    can i confirm with SQL expert here, why 1 or 0 is not accept for BIT datatype ? but only "true" or "false" are allow, is there anyway it can take 1 or 0 ?

    thank you !

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Try this:
    Code:
    DECLARE @b0    BIT
    ,  @b1	       BIT
    
    SET @b0 = 0
    SET @b1 = 1
    
    SELECT @b0, @b1
    -PatP

  3. #3
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    are you looking at access?
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  4. #4
    Join Date
    Dec 2007
    Location
    London, UK
    Posts
    741
    1 and 0 are the valid values for a BIT type in SQL Server. BIT is a numeric type.

    It's true that some tools such as Management Studio display TRUE and FALSE instead of 1 and 0 but that's just presentation. BIT is not a Boolean type

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    and, as far as i can recall from hearsay that i'm not sure i remember hearing, neither BIT nor BOOLEAN is standard SQL

    CHAR(1) or SMALLINT have the advantage of portability
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    ...and (in the case of SMALLINT), summability.
    If it's not practically useful, then it's practically useless.

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

  7. #7
    Join Date
    Mar 2004
    Posts
    74
    If BIT is numeric , when we do insertion , why we can't put in 0 or 1 but need 'True' or 'False' ?

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by alvincks
    If BIT is numeric , when we do insertion , why we can't put in 0 or 1 but need 'True' or 'False' ?
    See my exampe above, then we can discuss this in more detail.

    -PatP

  9. #9
    Join Date
    Dec 2007
    Location
    London, UK
    Posts
    741
    You CAN insert 1 or 0 into a BIT column. How are you inserting data? Through some GUI tool I would guess, in which case you are talking about a limitation of the tool, not of SQL Server.

  10. #10
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by dportas
    It's true that some tools such as Management Studio display TRUE and FALSE instead of 1 and 0
    It's not true to tar Management Studio with that brush - try running Pat's code.
    Quote Originally Posted by alvincks
    can i confirm with SQL expert here, why 1 or 0 is not accept for BIT datatype ? but only "true" or "false" are allow, is there anyway it can take 1 or 0 ?
    We can confirm that this is not correct - something else is at play here. Please respond to the questions above.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  11. #11
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by r937
    and, as far as i can recall from hearsay that i'm not sure i remember hearing, neither BIT nor BOOLEAN is standard SQL
    The BOOLEAN datatype was introduced with the ANSI SQL 99 standard.
    See: http://en.wikipedia.org/wiki/SQL:1999

  12. #12
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    thanks shammat

    (i still won't use BOOLEAN, though)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  13. #13
    Join Date
    Dec 2007
    Location
    London, UK
    Posts
    741
    Quote Originally Posted by pootle flump
    It's not true to tar Management Studio with that brush - try running Pat's code.
    In some places SSMS uses True/Fals; in others 1/0. Try editing a table and you'll see what I mean.

  14. #14
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Rly? I haven't ever edited a table (you mean the data in the table right?) in SSMS, and not in EM for about 5 years. I'll take your word for it
    Testimonial:
    pootle flump
    ur codings are working excelent.

  15. #15
    Join Date
    Mar 2004
    Posts
    74
    Hey Guys, i think the DB can insert the value of 1/0 , it might be caused by the coding side ....which take as string ....i need to confirm this ....thanks all for guidance and confirmation.

Posting Permissions

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