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,po_cycle,so_cycle,automin_flag,en_dis,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,item_sup_flag,item_stock,build_date,modify_date,stop_date,return_rate,abc,branch_price,item_rem,vip_price,sale_min_price,com_flag,base_price1,base_price2,base_price3,vip_acc_flag,vip_acc_num,dpfm_type
from #SDB..t_bd_item_info
##
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 = 'isszmv6' or #SV = 'isszmv7' or #SV = 'isszmv8' or #SV = 'isszmv9' or #TV = 'isszmv6' or #TV = 'isszmv7' or #TV = 'isszmv8' or #TV = 'isszmv9') 
	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 not (#SV = 'isszmv6' or #SV = 'isszmv7' or #SV = 'isszmv8' or #SV = 'isszmv9' or #TV = 'isszmv6' or #TV = 'isszmv7' or #TV = 'isszmv8' or #TV = 'isszmv9')
	exec('update t_bd_item_info set other1 = tab_a.other1,
									other2 = tab_a.other2,
									other3 = tab_a.other3,
									num1 = tab_a.num1,
									num2 = tab_a.num2,
									num3 = tab_a.num3,
									direct = tab_a.direct,
									lose_rate = tab_a.lose_rate,
									item_counter = tab_a.item_counter,
									sup_ly_rate = tab_a.sup_ly_rate,
									branch_no = tab_a.branch_no,
								    cost_compute = tab_a.cost_compute
		  from #SDB..t_bd_item_info as tab_a
		  where t_bd_item_info.item_no = tab_a.item_no ')
GO
if (#TV = 'isszmv6' or #TV = 'isszmv7' or #TV = 'isszmv8' or #TV = 'isszmv9' ) 
	if (#SV = 'isszmv6' or #SV = 'isszmv7' or #SV = 'isszmv8' or #SV = 'isszmv9')
		exec('update t_bd_item_info set measure_flag = tab_a.measure_flag,
										valid_days = isnull(tab_a.valid_days,0),
										sup_rate = isnull(tab_a.sup_rate,0)
			  from #SDB..t_bd_item_info as tab_a
			  where t_bd_item_info.item_no = tab_a.item_no')
	else
		exec('update t_bd_item_info set measure_flag = tab_a.num3,
										valid_days = isnull(tab_a.num2,0),
										sup_rate = isnull(tab_a.sup_ly_rate,0)
			  from #SDB..t_bd_item_info as tab_a
			  where t_bd_item_info.item_no = tab_a.item_no')
else
	if (#SV = 'isszmv6' or #SV = 'isszmv7' or #SV = 'isszmv8' or #SV = 'isszmv9')
		exec('update t_bd_item_info set num3 = tab_a.measure_flag,
										num2 = isnull(tab_a.valid_days,0),
										sup_ly_rate = isnull(tab_a.sup_rate,0)
			  from #SDB..t_bd_item_info as tab_a
			  where t_bd_item_info.item_no = tab_a.item_no')
	else
		exec('update t_bd_item_info set num3 = tab_a.num3,
										num2 = isnull(tab_a.num2,0),
										sup_ly_rate = isnull(tab_a.sup_ly_rate,0)
			  from #SDB..t_bd_item_info as tab_a
			  where t_bd_item_info.item_no = tab_a.item_no')

GO

if (#TV = 'hbposev9')
	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' or #TV = 'isszmv6' or #TV = 'isszmv7' or #TV = 'isszmv8' or #TV = 'isszmv9')
			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
