Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alter the boolean value in SQL Server select query?

Basically I want to alter the boolean value selecting from the table:

e.g.:

SELECT otherColumns, not ysnPending FROM table

I need a column ysnPending = true if the value is false & false if the value is true.

Is there any function available to alter the Boolean value or I should use IIf or CASE...?

like image 950
Vikas Avatar asked Mar 06 '10 06:03

Vikas


1 Answers

use CASE, or if the bit field is non-nullable you could just subtract from 1.

SELECT 
    otherColumns, 
    (1 - ysnPending) -- NOT ysnPending
FROM table 

(Using CASE might lead to more understandable code.)

If ysnPending is nullable, what behaviour do you assign to NOT?

like image 129
Mitch Wheat Avatar answered Sep 28 '22 00:09

Mitch Wheat