I need to write result of EXISTS function to a variable. I read that SQL Server has no ‘bool’ variables, so I want to store the result in a bit variable. And vice versa convert from ‘bit’ to ‘bool’. How can I achieve it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t know what vice versa means. SQL Server doesn’t have a boolean data type, so I don’t know what you want to convert a BIT to… maybe:
If you’re trying to do this in an
IFstatement:If you’re looking for shorthand, where you can say
IF (@bool)instead ofIF (@bool) = 1, sorry, but you’re out of luck. If this is where you are trying to “optimize” your code and you don’t have more pressing problems, go home for the day and have a beer, you’ve earned it. Saving two characters has already cost you more time than it will ever gain you.