Bit by bit

  • agrawal.prakriti

    Mr or Mrs. 500

    Points: 572

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

  • SanjayAttray

    SSChampion

    Points: 13157

    Easy one.

    SQL DBA.

  • M&M

    SSC-Insane

    Points: 21699

    Good question. Tests the basic 🙂

    M&M

  • Bhavesh_Patel

    SSCrazy

    Points: 2259

    Points for taking ... 😛



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

    http://bhaveshgpatel.wordpress.com/
  • WayneS

    SSC Guru

    Points: 95392

    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

  • SQLRNNR

    SSC Guru

    Points: 281252

    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

  • ziangij

    SSCertifiable

    Points: 7235

    easy one 😀

  • Toreador

    SSChampion

    Points: 11259

    "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.

  • Bob JH Cullen

    SSCrazy

    Points: 2082

    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?

  • Toreador

    SSChampion

    Points: 11259

    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"

  • Muhammad Haseeb Farhan

    Right there with Babe

    Points: 728

    This should worth of 100 points 🙂

  • Dave62

    SSCertifiable

    Points: 6697

    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

  • Cliff Jones

    SSChampion

    Points: 10517

    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.

  • Bob JH Cullen

    SSCrazy

    Points: 2082

    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.

  • Toreador

    SSChampion

    Points: 11259

    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 30 total)

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