A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @arkiboys
As others have said, it is not clear and may not be what you are looking for.
If col3 are both null.
This query is for the case where col1, col2, and col5 are join conditions
SQL
declare @tbl1 table(col1 int,col2 int,col3 int,col4 int,col5 int)
declare @tbl2 table(col1 int,col2 int,col3 int,col4 int,col5 int)
insert into @tbl1 values
(1,2,3,4,5),(1,2,null,4,5)
insert into @tbl2 values
(1,2,3,4,5),(1,2,null,4,5);
select *
from
@tbl1 as tbl1 inner join @tbl2 as tbl2
on
(tbl1.col3 is not null and tbl2.col3 is not null
and tbl1.col3 = tbl1.col3)
or
(tbl1.col3 is null and tbl2.col3 is null
and tbl1.col1 = tbl2.col1
and tbl1.col2 = tbl2.col2
and tbl1.col5 = tbl2.col5
);
OUTPUT