I have 4 tables one comman column (Date and Qty) and another field
I want to join 4 tables with date as comman column.Some times qty will be null for particular date. I want to display all the dates even when one of table qty is Null.
; with cte as
(
select Date, A, B = NULL, C = NULL, D = NULL
from table1
union all
select Date, A = NULL, B, C = NULL, D = NULL
from table2
union all
select Date, A = NULL, B = NULL, C, D = NULL
from table3
union all
select Date, A = NULL, B = NULL, C = NULL, D
from table4
)
select Date, MAX(A) AS A, MAX(B) AS B, MAX(C) AS C, MAX(D) AS D
from cte
group by Date