An example of using the case statement:
create table table1 (id int not null, ysnPending bit null) insert table1 values (1, 1) insert table1 values (2, null) insert table1 values (3, 0) select id, cast((case when ysnPending = 1 then 0 else 1 end) as bit) as Not_ysnPending from table1
It is assumed that you want to return 1 when ysnPending is NULL.
Cast to bit type โ Make sure the returned column is a BIT data type. If you leave it, it will return the INTEGER type. (This may or may not matter to you, depending on how you intend to use the returned result set).
Moe sisko
source share