TSQL

  • Muhammed Rafiq

    SSC Eights!

    Points: 921

    Comments posted to this topic are about the item TSQL

  • Paul White

    SSC Guru

    Points: 150442

    Good question today - a nice variation on the convert-to-BIT questions of the past. I will freely admit to guessing on this one!

  • Daniel Bowlin

    SSC-Dedicated

    Points: 34566

    It is learning about things like this....one little BIT at a time that make me better and better. Thanks.

  • webrunner

    SSC-Dedicated

    Points: 30303

    dbowlin (4/3/2010)


    It is learning about things like this....one little BIT at a time that make me better and better. Thanks.

    Ha ha - good one!

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • SanjayAttray

    SSChampion

    Points: 13157

    Simple and easy one.

    SQL DBA.

  • m--S3qU3L

    Hall of Fame

    Points: 3706

    Easy but brushing up the knowledge

    Thanks

    John

  • malleswarareddy_m

    SSCertifiable

    Points: 5847

    Good QOD.This Question gives good information about bit datatypes.

    when we use space or all zero it bit will convert it into zero.If we give numeric(numbers) it will convert it into one.

    declare @bit bit

    set @bit='233677788778'

    select @bit

    This gives 1 as output.

    declare @bit bit

    set @bit='00000'

    select @bit

    This gives 1 as output.

    declare @bit bit

    set @bit=' '

    select @bit

    This gives 0 as output.

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

  • vk-kirov

    SSCertifiable

    Points: 7686

    malleswarareddy_m (4/4/2010)


    declare @bit bit

    set @bit='00000'

    select @bit

    This gives 1 as output.

    This must be a typo because the result is 0.

  • SanjayAttray

    SSChampion

    Points: 13157

    malleswarareddy_m (4/4/2010)


    Good QOD.This Question gives good information about bit datatypes.

    when we use space or all zero it bit will convert it into zero.If we give numeric(numbers) it will convert it into one.

    Go through the discussion over this thread to get more info about bit.

    http://www.sqlservercentral.com/Forums/Topic854871-2605-1.aspx

    SQL DBA.

  • SQLRNNR

    SSC Guru

    Points: 281243

    Nice 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

  • john.arnott

    SSChampion

    Points: 11882

    malleswarareddy_m (4/4/2010)


    Good QOD.This Question gives good information about bit datatypes.

    when we use space or all zero it bit will convert it into zero.If we give numeric(numbers) it will convert it into one.

    . . . .

    This is true for other numeric datatypes as well. Spaces or empty strings are implicitly converted to zero

    DECLARE @MyNum int

    SET @MyNum = ' '

    -- attempt arithmetic operation

    Select @myNum * 4

    -- result is 0, not an error.

  • rjv_rnjn

    Hall of Fame

    Points: 3023

    john.arnott (4/5/2010)


    This is true for other numeric datatypes as well. Spaces or empty strings are implicitly converted to zero

    DECLARE @MyNum int

    SET @MyNum = ' '

    -- attempt arithmetic operation

    Select @myNum * 4

    -- result is 0, not an error.

    Good point, but I would like it more if SQL Server throws an exception and let developers know upfront that it's wrong to assign string/character values to an integer data type.

  • KevinC.

    SSCommitted

    Points: 1570

    It will throw an error if you attempt to assign a NON-empty string to an integer data type.

    I can see your point for an empty string/character value, but it does come in handy when you need to work with data where someone has set all the columns that should be integer to text :crazy:

  • malleswarareddy_m

    SSCertifiable

    Points: 5847

    vk-kirov (4/5/2010)


    malleswarareddy_m (4/4/2010)


    declare @bit bit

    set @bit='00000'

    select @bit

    This gives 1 as output.

    This must be a typo because the result is 0.

    Yes it will give zero as ouptut. Some typing mistake.

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

  • malleswarareddy_m

    SSCertifiable

    Points: 5847

    john.arnott (4/5/2010)


    malleswarareddy_m (4/4/2010)


    Good QOD.This Question gives good information about bit datatypes.

    when we use space or all zero it bit will convert it into zero.If we give numeric(numbers) it will convert it into one.

    . . . .

    This is true for other numeric datatypes as well. Spaces or empty strings are implicitly converted to zero

    DECLARE @MyNum int

    SET @MyNum = ' '

    -- attempt arithmetic operation

    Select @myNum * 4

    -- result is 0, not an error.

    I think it will throw error when converting it to string datatype except(TRUE/False)

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

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

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