I have an SQL statement that joins to two different tables in a 1 to 1 relationship each. For each of those joins, I want to return a BIT
value (0 or 1), if the join was successful or not.
Let's say, we have a base table Base
and the tables A
and B
, which are joined together via a LEFT JOIN
on a common ID. I want to return the ID, as well as a field IsA
and a field IsB
.
What would be the best-practice solution to do this in Microsoft SQL Server most efficiently?
By the way, my current approach is this:
CAST(ISNULL(A.ID, 0) AS BIT) AS IsA,
CAST(ISNULL(B.ID, 0) AS BIT) AS IsB