Bit by bit

  • Comments posted to this topic are about the item Bit by bit

  • Easy one.

    SQL DBA.

  • Good question. Tests the basic 🙂

    M&M

  • Points for taking ... 😛



    [font="System"]Bhavesh Patel[/font]

    http://bhaveshgpatel.wordpress.com/
  • Bhavesh_Patel (1/27/2010)


    Points for taking ... 😛

    Makes up for yesterdays (though points were awarded anyway...)

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Thanks for the question.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • easy one 😀

  • "if a number larger than one is used, it is converted to one."

    I thought the actual explanation was that anything other than 0 (false) is treated as true and hence is stored as 1. So a number larger than 1 becomes 1, but so does any number less than 1, apart from 0.

  • OK. I am in the 17% who got it wrong - I replied "Error". And now I know. But will somebody kindly explain why BIT is treated any differently to TINYINT, SMALLINT, INT, etc. It is, after all, only a type that has a range of valid values. If the others report an overflow error when I try to assign values outside their permitted range, why not BIT also?

  • Here's a slightly better reference

    http://msdn.microsoft.com/en-us/library/ms191530(SQL.90).aspx#_bit

    "Converting to bit promotes any nonzero value to 1"

  • This should worth of 100 points 🙂

  • Bob Cullen-434885 (1/28/2010)


    OK. I am in the 17% who got it wrong - I replied "Error". And now I know. But will somebody kindly explain why BIT is treated any differently to TINYINT, SMALLINT, INT, etc. It is, after all, only a type that has a range of valid values. If the others report an overflow error when I try to assign values outside their permitted range, why not BIT also?

    I think it is because the BIT type is supposed to represent True (1) or False (0) rather than integers.

    Dave

  • Toreador (1/28/2010)


    "if a number larger than one is used, it is converted to one."

    I thought the actual explanation was that anything other than 0 (false) is treated as true and hence is stored as 1. So a number larger than 1 becomes 1, but so does any number less than 1, apart from 0.

    I agree. Any numeric value other than 0. It will also apply to -1.3434. It does not have to be larger than 0.

  • Dave62 (1/28/2010)

    I think it is because the BIT type is supposed to represent True (1) or False (0) rather than integers.

    Dave

    Ah! So a BOOLEAN type, then. That's different, and if so should also require that the language provides proper TRUE and FALSE keywords, rather than hijacking numeric values like 0, 1, pi or whatever.

  • Bob Cullen-434885 (1/28/2010)


    Ah! So a BOOLEAN type, then. That's different, and if so should also require that the language provides proper TRUE and FALSE keywords, rather than hijacking numeric values like 0, 1, pi or whatever.

    True and False are also accepted.

    DECLARE @bit BIT

    SET @bit = 'false'

    PRINT @bit

    SET @bit = 'true'

    PRINT @bit

Viewing 15 posts - 1 through 15 (of 29 total)

You must be logged in to reply to this topic. Login to reply