A way to compare SQL bit to char in two different tables

Viewed 54

I have two tables, table A with column A which takes a bit value and Table B with column B that takes a Char(1) value the values are either 'C' or 'D' and I want them to match the bit of 0 or 1 respectively is there a way I can compare these two like so?

Thanks!

1 Answers

You could enumerate the combinations. Say you want a match, then use the following condition:

(ta.a = 0 and tb.b = 'C') or (ta.a = 1 and tb.b = 'D')

Alternatively, use a case expression:

ta.a = case tb.b when 'C' then 0 when 'D' then 1 end
Related