select '' as item_no from sysobjects with(nolock) where 1=2
##
if not (#SV = 'kmjxc_pro' or #SV = 'kmjxc_std' or #SV = 'bw9kbzpro' or #SV = 'tiger')
	begin
		if (#TV = 'hbyjtv6' or #TV = 'hbyjtv7' or #TV = 'hbyjtv8' or #TV = 'hbposv5')
			exec('insert t_bd_supcust_item (item_no,supcust_no,sale_way,contract_date)
				 select a.item_no, a.main_supcust,max(a.item_sup_flag) as item_sup_flag,getdate()
				   from t_bd_item_info a, t_bd_branch_info b
				 where (b.property = ''1'' or (b.property = ''0'' and b.trade_type in (''1'',''3'')) )
				   and not exists (select 1 from t_bd_supcust_item c 
									  where c.item_no = a.item_no 
										and c.supcust_no = a.main_supcust)
				  group by a.item_no, a.main_supcust ')
		          
		else
			exec('insert t_bd_supcust_item (branch_no,item_no,supcust_no,sale_way,contract_date)
				 select b.branch_no,a.item_no, a.main_supcust,a.item_sup_flag,getdate()
				   from t_bd_item_info a, t_bd_branch_info b
				 where (b.property = ''1'' or (b.property = ''0'' and b.trade_type in (''1'',''3'')) )
				   and not exists (select 1 from t_bd_supcust_item c 
									  where c.branch_no = b.branch_no
										and c.item_no = a.item_no 
										and c.supcust_no = a.main_supcust )')
	end
GO