select '' as  item_no from sysobjects with(nolock) where 1=2
##
if #SV = 'kmjxc_pro' 
	exec('insert into t_bd_item_info (item_no,item_subno,item_name,item_subname,item_clsno,item_brand,item_brandname,unit_no,item_size,product_area,price,base_price,sale_price,combine_sta,status,display_flag,other1,other2 ,other3 ,num1,num2,main_supcust,item_sup_flag ,sup_ly_rate,vip_price,dpfm_type,vip_acc_flag,num3) 
		  select item_no,isnull(item_subno,''0''),item_name,item_subname,item_clsno,item_brand,item_brandname,unit_no,item_size,product_area,isnull(price,0),isnull(base_price,0),isnull(sale_price,0),combine_sta,status,display_flag,other1,other2 ,other3,num1,num2,case when sup_no is null then ''0'' when len(sup_no) > 8 then ''0'' else sup_no end,''A'' ,ly_deduct,vip_price,''0'',''0'',(case flag2 when ''Z'' then 1 when ''J'' then 2 else 0 end) from #SDB..bi_t_item_info')
else if #SV = 'kmjxc_std'
	exec('insert into t_bd_item_info (item_no,item_subno,item_name,item_subname,item_clsno,item_brand,item_brandname,unit_no,item_size,product_area,price,base_price,sale_price,combine_sta,status,display_flag,other1,other2 ,other3 ,num1,num2,main_supcust,item_sup_flag ,sup_ly_rate,vip_price,dpfm_type,vip_acc_flag) 
		  select item_no,isnull(item_subno,''0''),item_name,item_subname,item_clsno,case item_brand when ''QS'' then ''PP'' else item_brand end,item_brandname,unit_no,item_size,product_area,isnull(price,0),isnull(base_price,0),isnull(sale_price,0),combine_sta,status,display_flag,other1,other2 ,other3,num1,num2,case when sup_no is null then ''0'' when len(sup_no) > 8 then ''0'' else sup_no end,''A'' ,0,0,''0'',''0''  from SDB..bi_t_item_info')
else if #SV = 'bw9kbzpro'
	exec('insert into t_bd_item_info(item_no, item_subno, item_name, item_subname, item_clsno, item_brand,item_sup_flag,item_brandname, unit_no, item_size, product_area, price, base_price, sale_price,combine_sta, status, other1, other2, other3, num3,num2,num1,sup_ly_rate, main_supcust,purchase_spec,purchase_tax,sale_tax, item_counter,vip_price,vip_acc_flag,vip_acc_num, item_stock,en_dis, change_price,build_date,modify_date,build_man,last_modi_man)
		 SELECT barcode,item_subno, item_name, item_subname, item_clsno, item_brand,sale_no,item_brandname, unit_no, item_size, product_area, price, base_price, sale_price,(case combine_sta when ''5'' then ''2'' when ''6'' then ''3'' when ''7'' then ''6'' when ''8'' then ''7'' else ''0'' end) ,(case display_flag when ''0'' then ''2'' when ''3'' then ''0'' when ''2'' then ''1'' else display_flag end ), item_other1, item_other2, item_other3, 
		 (case item_flag when ''0'' then ''0'' when ''1'' then ''1'' else ''2'' end ),valid_day,item_num1,ly_kl,sup_no,1,item_in_tax, item_out_tax, (case counter_code when ''0'' then ''9999'' else counter_code end), vip_price,(case when integral_rate>0 then ''1'' else ''0'' END),(case when integral_rate>0 then integral_rate else 0 end),(case have_stock when ''0'' then ''1'' else ''0'' end ),allow_discount,change_price,getdate(),getdate(),''1001'',''1001'' 
		 FROM  #SDB..bi_t_item_info where  barcode not in (select barcode from  #SDB..bi_t_item_info  group by barcode having count(*)>1)')
else if #SV = 'tiger'
	exec('insert into t_bd_item_info(item_no, item_subno, item_name, item_subname, item_clsno, item_brand,item_brandname, unit_no, item_size, product_area, price, base_price, sale_price,combine_sta, status, display_flag, other1, other2, other3, num3, num1, num2,po_cycle, main_supcust,purchase_spec,purchase_tax,sale_tax,item_counter,item_rem,vip_price,vip_acc_flag, en_dis, change_price) 
		SELECT ltrim(rtrim(item_no)), isnull(item_subno,''0''), item_name, item_subname, class_no, brand_no,brand_noname, unit_no, item_size, product_area, price, base_price, sale_price,combine_sta, status, display_flag, other1, other2, other3, num1, num2, num3,buy_cycle, isnull(ltrim(rtrim(sup_no)),''0''),in_stock_factor,  buy_tax, sale_tax, counter_no,item_no5,item_no2,(case item_no6 when ''0'' then ''1'' when ''1'' then ''0'' END),changepx_flag,changepx_flag 
		FROM #SDB..item  where ltrim(rtrim(item_no))<>'''' ')
else
	exec('insert into t_bd_item_info (item_no,item_subno,item_name,item_subname,item_clsno,item_brand,item_brandname,unit_no,item_size,product_area,price,base_price,sale_price,combine_sta,status,display_flag,other1,other2,other3,num1,num2,num3,po_cycle,so_cycle,automin_flag,en_dis,direct,change_price,purchase_tax,sale_tax,purchase_spec,shipment_spec,item_supcust,main_supcust,lose_rate,item_sup_flag,item_stock,item_counter,sup_ly_rate,build_date,modify_date,stop_date,return_rate,abc,branch_price,item_rem,vip_price,sale_min_price,branch_no,cost_compute,com_flag,base_price1,base_price2,base_price3,vip_acc_flag,vip_acc_num,dpfm_type)
		  select item_no,item_subno,item_name,item_subname,item_clsno,item_brand,item_brandname,unit_no,item_size,product_area,price,base_price,sale_price,combine_sta,status,display_flag,other1,other2,other3,num1,num2,num3,po_cycle,so_cycle,automin_flag,en_dis,direct,change_price,purchase_tax,sale_tax,purchase_spec,shipment_spec,item_supcust,(case when main_supcust is null then ''0'' else main_supcust end) main_supcust,lose_rate,item_sup_flag,item_stock,item_counter,sup_ly_rate,build_date,modify_date,stop_date,return_rate,abc,branch_price,item_rem,vip_price,sale_min_price,branch_no,cost_compute,com_flag,base_price1,base_price2,base_price3,vip_acc_flag,vip_acc_num,dpfm_type
		  from #SDB..t_bd_item_info')

if (#SV = 'kmjxc_pro')
	exec('update t_bd_item_info set other2=item_subno,item_subno=item_no where num3=2 or num3 = 1')
if ((#SV = 'kmjxc_pro' or #SV = 'kmjxc_std'))
	exec('update t_bd_item_info set item_brand = right(rtrim(item_brand),4) where item_brand<''9999'' and len(rtrim(item_brand))=5 and item_brand is not null')

go		  
if (#SV = 'hbposv7' or #SV = 'hbposv8' or #SV = 'hbposev8' or #SV = 'hbposev9') and
	(#TV = 'hbposv7' or #TV = 'hbposv8' or #TV = 'hbposev8' or #TV = 'hbposev9')
	exec('update t_bd_item_info set vip_price1 = tab_a.vip_price1,
									vip_price2 = tab_a.vip_price2,
									base_price4 = tab_a.base_price4,
									build_man = tab_a.build_man,
									last_modi_man = tab_a.last_modi_man,
									order_man_rate = tab_a.order_man_rate,
									trans_price = tab_a.price
		  from #SDB..t_bd_item_info as tab_a
		  where t_bd_item_info.item_no = tab_a.item_no ')
GO
if (#TV = 'hbposv7' or #TV = 'hbposv8' or #TV = 'hbposev8' or #TV = 'hbposev9')
	exec('update t_bd_item_info set base_price4 = isnull(base_price4,0),
									build_man = (case when isnull(build_man,'''') =  '''' then ''1001'' else build_man end),
									last_modi_man = (case when isnull(last_modi_man,'''') =  '''' then ''1001'' else last_modi_man end),
									order_man_rate = isnull(order_man_rate,0)')
GO
if not (#SV = 'hbposv5' or #SV = 'hbyjtv6' or #SV = 'hbyjtv7' or #SV = 'hbyjtv8' or #TV = 'hbposv5' or #TV = 'hbyjtv6' or #TV = 'hbyjtv7' or #TV = 'hbyjtv8' or 
		#SV = 'kmjxc_pro' or #SV = 'kmjxc_std' or #SV = 'bw9kbzpro' or #SV = 'tiger' )
	exec('update t_bd_item_info set trans_price = tab_a.price
		  from #SDB..t_bd_item_info as tab_a
		  where t_bd_item_info.item_no = tab_a.item_no ')	
GO
if (#TV = 'hbposev9')and (not (#SV = 'bw9kbzpro' or #SV = 'tiger' ))
	exec('update t_bd_item_info set status = (case status when  ''0'' then ''3'' when ''1'' then ''2''  when ''2'' then ''5''  when ''3'' then ''4''  when ''4'' then ''3''  else ''0''  end)')
GO
if (#SV = 'hbposev9')
	begin
		if (#TV = 'hbposv5' or #TV = 'hbyjtv6' or #TV = 'hbyjtv7' or #TV = 'hbyjtv8')
			exec('update t_bd_item_info set status = (case when status in (''0'',''1'',''2'') then ''1'' else ''0''  end)')
		else
			exec('update t_bd_item_info set status = (case status when  ''0'' then ''2'' when ''1'' then ''2''  when ''2'' then ''1''  when ''3'' then ''0''  when ''4'' then ''3'' when ''5'' then ''2'' when ''6'' then ''2''  else ''1''  end)')
	end
else
	begin
		if (#TV = 'hbposv5' or #TV = 'hbyjtv6' or #TV = 'hbyjtv7' or #TV = 'hbyjtv8')
			exec('update t_bd_item_info set status = (case when status = ''1'' then ''1'' else ''0''  end)')
	end

GO
