问:多个独立的单店数据怎么合并到一个总部去?(复杂完整版)
答:
这个是非常麻烦的,要有强大的心理准备以及技术实力。
核心指导思想:
先弄总部,以某个店为准当做是总部,再把其它的门店数据逐个合并进来;
合并时先搞和商品相关基础资料,如:供应商、商品等,再搞价格、库存、会员等;
对于商品,建议只合并标准EAN13码的,非EAN13码的大部分是生鲜,以总部为准,不合并分店的。
详细步骤为:
1、把分店的老数据库备份,拿到总部的SQL企业管理器里还原成泰格金霸软件的数据库名字tigerjb..
2、处理供应商:
A、执行下面的命令,显示哪些资料是编号相同名称不同,由于编号重复了就不能插入到总部,所以要先找出来
select a.sup_no, a.sup_name, a.sup_linkman_b, a.mobile_no, a.sup_address_b
from tigerjb..ba_sup_info a
inner join ba_sup_info b
on a.sup_no = b.sup_no
and a.sup_name <> b.sup_name
order by a.sup_no
B、执行APPFIX,选tigerjb数据库,替换供应商编号,把重复的供应商替换为一个新的供应商编号,所有重复的都要替换,除非不导入
C、执行下面的命令,把分店有总部无的供应商,插入到总部
insert ba_sup_info
select a.*
from tigerjb..ba_sup_info a
left join ba_sup_info b
on a.sup_no = b.sup_no
where b.sup_no is null
3、处理类别资料,逻辑同供应商
A、执行下面的命令,显示哪些资料是编号相同名称不同,由于编号重复了就不能插入到总部,所以要先找出来
select a.class_no, a.class_name
from tigerjb..ba_cls_info a
inner join ba_cls_info b
on a.class_no = b.class_no
and a.class_name <> b.class_name
order by a.class_no
B、执行APPFIX,选tigerjb数据库,替换类别编号,把重复的类别编号替换为一个新的类别编号,所有重复的都要替换,除非不导入
C、执行下面的命令,把分店有总部无的类别,插入到总部
insert ba_cls_info
select a.*
from tigerjb..ba_cls_info a
left join ba_cls_info b
on a.class_no = b.class_no
where b.class_no is null
4、处理商品资料
A、对于分店、总部都有的13位条码,可以不管,以总部的货号为准
B、对于非标准的13位条码,建议以总部为准,分店的不要插入总部,缺少的在总部里重新建立(手工完成)
C、插入分店有总部无的标准13位条码的非一码多品商品,插入时货号不能用分店库里的货号,因为会重复,要改为用条码
alter table item disable trigger all
insert item
select rtrim(f.item_subno), f.item_subno, f.item_name, f.item_subname, f.pym, f.class_no, f.brand_no, f.unit_no, f.item_size, f.product_area, f.third_party_no, f.counter_no, f.sup_no, f.in_price, f.base_price, f.sale_price, f.vip_price, f.sub_price_flag, f.counter_subrate, f.counter_spec_subrate, f.sup_salerate, f.sup_spec_salerate, f.in_stock_unit, f.in_stock_factor, f.in_stock_size, f.buy_tax, f.sale_tax, f.buy_cycle, f.arrive_cycle, f.shelf_day, f.waste_rate, f.branch_buy, f.stop_buy, f.display_flag, f.sale_type, f.weight_flag, f.stock_flag, f.changepx_flag, f.class_abc, f.class_28, f.grade, f.item_type, f.bind_flag,
item_son_no = isnull(son.item_subno, f.item_son_no),
f.item_son_qty, f.oper_id, f.oper_date, f.num1, f.num2, f.num3, f.num4, f.num5, f.flag1, f.flag2, f.flag3, f.flag4, f.flag5, f.other1, f.other2, f.other3, f.other4, f.other5, f.depart_no, f.item_en_name, f.init_qty, f.po_min_qty, f.create_id, f.create_date
from tigerjb..item f
left join item z on z.item_subno = f.item_subno or z.item_no = f.item_subno
left join tigerjb..item son on son.item_no = f.item_son_no and f.bind_flag = '1'
left join (select item_subno from tigerjb..item where datalength(rtrim(item_subno)) = 13 group by item_subno having count(1) > 1) ymdp on ymdp.item_subno = f.item_subno
where datalength(rtrim(f.item_subno)) = 13
and z.item_no is null
and ymdp.item_subno is null
alter table item enable trigger all
补充,若想把门店非EAN13位的非生鲜商品插入到总部,那就执行这个(不插入就不执行)
alter table item disable trigger all
insert item
select f.item_no, f.item_subno, f.item_name, f.item_subname, f.pym, f.class_no, f.brand_no, f.unit_no, f.item_size, f.product_area, f.third_party_no, f.counter_no, f.sup_no, f.in_price, f.base_price, f.sale_price, f.vip_price, f.sub_price_flag, f.counter_subrate, f.counter_spec_subrate, f.sup_salerate, f.sup_spec_salerate, f.in_stock_unit, f.in_stock_factor, f.in_stock_size, f.buy_tax, f.sale_tax, f.buy_cycle, f.arrive_cycle, f.shelf_day, f.waste_rate, f.branch_buy, f.stop_buy, f.display_flag, f.sale_type, f.weight_flag, f.stock_flag, f.changepx_flag, f.class_abc, f.class_28, f.grade, f.item_type, f.bind_flag,
item_son_no = isnull(son.item_subno, f.item_son_no),
f.item_son_qty, f.oper_id, f.oper_date, f.num1, f.num2, f.num3, f.num4, f.num5, f.flag1, f.flag2, f.flag3, f.flag4, f.flag5, f.other1, f.other2, f.other3, f.other4, f.other5, f.depart_no, f.item_en_name, f.init_qty, f.po_min_qty, f.create_id, f.create_date
from tigerjb..item f
left join item z on z.item_subno = f.item_subno or z.item_no = f.item_subno or z.item_no = f.item_no
where datalength(rtrim(f.item_subno)) not in(5, 13 )
and z.item_no is null
alter table item enable trigger all
D、列出分店库里有总部无的标准13位条码的一码多品商品,人为处理要怎么搞
select f.item_no, f.item_subno, f.item_name, f.in_price, f.sale_price
from tigerjb..item f
inner join (select item_subno from tigerjb..item where datalength(rtrim(item_subno)) = 13 group by item_subno having count(1) > 1) ymdp on ymdp.item_subno = f.item_subno
order by f.item_subno, f.item_no
E、插入分店有总部无的标准13位的一品多码的商品,同样插入时货号不能用分店库里的货号,因为会重复,要改为用条码
insert ba_multi_item
select f.plu_no, f.plu_no, f.remark
from tigerjb..ba_multi_item f
left join item z1 on z1.item_subno = f.plu_no
left join ba_multi_item z2 on z2.plu_no = f.plu_no
where z1.item_no is null
and z2.item_no is null
==找一个良道吉日,晚上营业结束日结后,把分店标准13位条码的商品的售价、特价、库存数据导入到总部去,假设分店编号是02
6、导入分店商品售价到总部
delete ba_branch_sale_price where branch_no = '02'
insert ba_branch_sale_price(branch_no, item_no, sale_price, statue, oper_date, memo)
select '02', a.item_no, b.sale_price, 'Y', getdate(), ''
from item a
inner join tigerjb..item b on a.item_subno = b.item_subno and b.sale_price <> a.sale_price
where datalength(rtrim(a.item_subno)) = 13
7、导入分店特价到总部
delete pm_spec_price where branch_no = '02'
insert pm_spec_price(branch_no, item_no, special_type, start_date, end_date, old_price, spe_price, discount, sale_qty, sold_qty, other1, other2, other3, total_spec_qty, spec_need_integral, spec_week_day, spec_month_day, flag1, flag2, num1, num2, vip_type, spec_subject, in_price_flag)
select '02', a.item_no, s.special_type, s.start_date, s.end_date, s.old_price, s.spe_price, s.discount, s.sale_qty, s.sold_qty, s.other1, s.other2, s.other3, s.total_spec_qty, s.spec_need_integral, s.spec_week_day, s.spec_month_day, s.flag1, s.flag2, s.num1, s.num2, s.vip_type, s.spec_subject, s.in_price_flag
from item a
inner join tigerjb..item b on a.item_subno = b.item_subno
inner join tigerjb..pm_spec_price s on b.item_no = s.item_no
where datalength(rtrim(a.item_subno)) = 13
8、导入分店库存到总部
delete wh_stock where branch_no = '02'
insert wh_stock
select '02', a.item_no, sum(s.stock_qty), max(s.cost_price), '1'
from item a
inner join tigerjb..item b on a.item_subno = b.item_subno
inner join tigerjb..wh_stock s on b.item_no = s.item_no
where datalength(rtrim(a.item_subno)) = 13
group by a.item_no
9、导入分店会员到总部
if (
select count(1)
from tigerjb..pos_vip_info a
inner join pos_vip_info b
on a.card_id = b.card_id
) > 0
begin
print '错误,分店跟总部存在相同的会员卡号,不能合并'
return
End
else
begin
alter table pos_vip_info disable trigger all
insert pos_vip_info
select a.*
from tigerjb..pos_vip_info a
left join pos_vip_info b on a.card_id = b.card_id
where b.card_id is null
alter table pos_vip_info enable trigger all
end
10、导入分店储值卡到总部
if (
select count(1)
from tigerjb..pos_saving_card_info a
inner join pos_saving_card_info b
on a.card_id = b.card_id
) > 0
begin
print '错误,分店跟总部存在相同的储值卡号,不能合并'
return
End
else
begin
alter table pos_saving_card_info disable trigger all
insert pos_saving_card_info
select a.*
from tigerjb..pos_saving_card_info a
left join pos_saving_card_info b on a.card_id = b.card_id
where b.card_id is null
alter table pos_saving_card_info enable trigger all
end