June 5, 2014 at 6:50 am
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. 🙂
June 5, 2014 at 7:03 am
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'.
June 5, 2014 at 7:11 am
Thanks for the question, Gerald.
June 5, 2014 at 7:23 am
This was removed by the editor as SPAM
June 5, 2014 at 7:25 am
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
June 5, 2014 at 7:38 am
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
June 5, 2014 at 7:45 am
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."
June 9, 2014 at 3:02 am
Nice question, good way to think about bit data type
June 9, 2014 at 10:22 am
easy one.
thanks for the question.
June 11, 2014 at 6:32 am
Thanks for the question!
July 13, 2014 at 11:32 pm
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