Fastest way to convert strings 'TRUE' and 'FALSE' to bit-values 1 and

  • Worried a bit when I saw "easiest", due to the subjectivity involved. But, thanks for the question!

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • Thomas Abraham (6/5/2014)


    Worried a bit when I saw "easiest", due to the subjectivity involved. But, thanks for the question!

    Yea, easiest for me generally means the most reliable and fault-tolerant, but it seemed pretty clear Gerald wanted us to pick the shortest/simplest solution.

    Nice question BTW. 🙂

  • Good question.

    As usual, though, "easiest" translates to "how you should most often not do it".

    If @TrueFalse is anything other than 'TRUE', 'FALSE', '', or an integer string, you'll get an error, and '' will return FALSE and not NULL.

    So use this method if and only if you can be absolutely sure that @TrueFalse will never be anything but 'TRUE' or 'FALSE'.

  • Thanks for the question, Gerald.

  • This was removed by the editor as SPAM

  • Ed Wagner (6/5/2014)


    It's nice to have a simple question every once in a while. Thanks.

    This is the type of question that makes me REALLY think about the data type and how it works under the hood. Once you explore how it really works, it can help when you're writing code.

    +1 Thanks for the question



    Everything is awesome!

  • Clive Strong (6/5/2014)


    I did pick the right option. However, all 3 could be the easiest, depending on your coding style.

    Alternatively, you don't need the CAST.

    SET @boolean = @TrueFalse

    works just fine, too.

    That`s what I call easy 😀

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

  • The question was cute - the correct answer is unfortunately 'obtuse' code that really has no place in a production environment.

    think "Code with clarity" ...

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • Nice question, good way to think about bit data type

  • easy one.

    thanks for the question.

  • Thanks for the question!

  • pchirags (6/9/2014)


    easy one.

    thanks for the question.

    +1

    Thanks

Viewing 12 posts - 16 through 26 (of 26 total)

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