方法一:
;with tb1 as (
select M.產編,T1.日期
From 資料庫Now.table M
Left outer join 資料庫Now.Table出貨紀錄 T1 on M.產編 = T1.產編
Where 條件 T1.xx = xxx.....
),
tb2 as (
select M.產編,T1.日期
From 資料庫2013.table M
Left outer join 資料庫2013.Table出貨紀錄 T1 on M.產編 = T1.產編
Where 條件 T1.xx = xxx.....
),
tb3 as (
select * from tb1
union all
select * from tb2
)
select 產編,max(日期) as 最近日期
from tb3
group by 產編