if exists ( select * from INFORMATION_SCHEMA.tables
where table_name = 'Config_Order_ChargesToPreView')
drop table Config_Order_ChargesToPreView
select * into Config_Order_ChargesToPreView from Config_Order_Charges
select HMNUM
, case when ISNULL(SubHMNUM, '') = '' then HMNUM else SubHMNUM end as SubHMNUM
, pc.ParcelSize
into #pc
from ProductCartons pc inner join (
select MAX(ProductCartonsID) as id
from ProductCartons
group by HMNUM, case when ISNULL(SubHMNUM, '') = '' then HMNUM else SubHMNUM end
) b on pc.ProductCartonsID = b.id