|
|
发表于 2008/9/16 10:37:05
|
显示全部楼层
--取最新销货日期
--取最新销货日期
select ps_dd,prd_no,wh into #b1 from tf_pss where wh in('07') and ps_id='SA'
union
select ps_dd,prd_no,wh from db_xx06.dbo.tf_pss where wh in('07') and ps_id='SA'
union
select ps_dd,prd_no,wh from db_xx05.dbo.tf_pss where wh in('07') and ps_id='SA'
select prd_no,wh,max(ps_dd) ps_dd into #b2 from #b1 group by prd_no,wh --取最新日期
select a.prd_no,a.name,a.wh,b.ps_dd from prdt a left outer join #b2 b on(a.prd_no=b.prd_no) where a.wh in('07') order by a.wh,a.prd_no |
|