A B C Equal 1 1 1 Y 2 2 NULL N
Hi, I have 3 columns which I need to compare : Columns A,B,C. If these 3 columns are the same then column 'Equal' = 'Y'
But, if a column is null, then it must be excluded from the comparison, e.g. in the example Row 2 has a null, but the remaining columns are all the same, so the Equal should be yes - because all non-null values are equal
I thought I could use isnull(C,A) = A but it does not work. Could anyone help please
declare @t table ( A decimal,B decimal, C decimal ) insert Into @t(A,B,C) values (1,1,1) insert Into @t(A,B) values (2,2) select A,B,C,'Equal' = case when ISNULL(A,B) = B and ISNULL(B,C) = C and ISNULL(C,A) = A then 'Y' else '' end from @t