TSQL

  • Comments posted to this topic are about the item TSQL

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

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

  • 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

  • Simple and easy one.

    SQL DBA.

  • Easy but brushing up the knowledge

    Thanks

    John

  • 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)

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

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

  • 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

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

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

  • 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:

  • 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)

  • 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 25 total)

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