select '' as cashier_id from sysobjects with(nolock) where 1=2
##

declare @ls_where varchar(255)
set @ls_where = '1=1'
if #SV <> 'hbyjtv8' and #TV <> 'hbyjtv8' 
	set @ls_where = @ls_where + ' and 1=1'
else
	set @ls_where = @ls_where + ' and 1=2'
	
if (#SV = 'kmjxc_pro' or #SV = 'kmjxc_pro')
	exec('insert into t_rm_cashier(cashier_id,cashier_name,cashier_pw,cashier_grant,cashier_status,discount_rate)
		  select cashier_id,cashier_name,cashier_id,''00000000000000000'',cashier_status,1
		  from #SDB..pos_t_cashier where ' + @ls_where)
else if #SV = 'bw9kbzpro'
	exec('insert into t_rm_cashier(cashier_id,cashier_name,cashier_pw,cashier_grant,cashier_status) 
		  SELECT oper_id,oper_name,'''',''0000000000000000000000'', ''正常''  
		  FROM  #SDB..sa_t_operator_i WHERE oper_id not in (''1001'',''9999'') and oper_type =''3000'' 
		  where ' + @ls_where)
else if #SV = 'tiger'
	exec('insert into t_rm_cashier(cashier_id,cashier_name,cashier_pw,cashier_grant,cashier_status)
          select cashier_id,cashier_name,'''',''0000000000000000000000'',cashier_status 
          from #SDB..pos_cashier_info where cashier_id not in(''1001'',''9999'') and ' + @ls_where)
else
	begin
		exec('insert into t_rm_cashier (cashier_id,cashier_name,cashier_pw,cashier_grant,cashier_status,discount_rate,num1,num2,other1,other2)
			  select cashier_id,cashier_name,cashier_pw,cashier_grant,cashier_status,discount_rate,num1,num2,other1,other2 
			  from #SDB..t_rm_cashier where ' + @ls_where)		  
	end

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')
	begin
	   exec('update t_rm_cashier set branch_no = tab_a.branch_no
			 from #SDB..t_rm_cashier as tab_a
			 where t_rm_cashier.cashier_id = tab_a.cashier_id')
	   exec('update t_rm_cashier set branch_no=isnull(t_bd_branch_info.branch_no,''00'')
			from t_bd_branch_info
			where isnull(t_rm_cashier.branch_no,'''') = '''' and
					t_bd_branch_info.property = ''1'' ')
	end
GO
if (#TV = 'hbyjtv8')
	begin
		if (#SV = 'kmjxc_pro' or #SV = 'kmjxc_pro')
			exec('insert into t_sys_operator (oper_id ,oper_name ,oper_pw,cash_grant ,cashier_status,discount_rate,num1)
				  select cashier_id,cashier_name,cashier_id,''00000000000000000'',cashier_status,1,0
				  from #SDB..pos_t_cashier')
		else if #SV = 'bw9kbzpro'
			exec('insert into t_sys_operator (oper_id ,oper_name ,oper_pw,cash_grant ,cashier_status) 
				  SELECT oper_id,oper_name,'''',''0000000000000000000000'', ''正常''  
				  FROM  #SDB..sa_t_operator_i WHERE oper_id not in (''1001'',''9999'') and oper_type =''3000'' ')
		else if #SV = 'tiger'
			exec('insert into t_sys_operator (oper_id ,oper_name ,oper_pw,cash_grant ,cashier_status)
				  select cashier_id,cashier_name,'''',''0000000000000000000000'',cashier_status 
				  from #SDB..pos_cashier_info where cashier_id not in(''1001'',''9999'')')
		else
			begin
				exec('insert into t_sys_operator (oper_id ,oper_name ,oper_pw,cash_grant ,cashier_status,discount_rate,num1)
					  select cashier_id,cashier_name,cashier_pw,cashier_grant,cashier_status,discount_rate,num1
					  from #SDB..t_rm_cashier as tab_a
					  where tab_a.cashier_id not in (select oper_id from t_sys_operator)')
				exec('update t_sys_operator set cash_grant = tab_a.cashier_grant,
												cashier_status = tab_a.cashier_status,
												discount_rate = tab_a.discount_rate,
												num1 = tab_a.num1
					  from #SDB..t_rm_cashier as tab_a
					  where t_sys_operator.oper_id = tab_a.cashier_id')
			end
	end

GO
if (#SV = 'hbyjtv8') 
	exec('insert into t_rm_cashier (cashier_id,cashier_name,cashier_pw,cashier_grant,cashier_status,discount_rate,num1,num2,other1,other2)
		  select oper_id as cashier_id,oper_name as cashier_name,oper_id as cashier_pw,cash_grant as cashier_grant,cashier_status,discount_rate,0 as num1,0 as num2,'''' as other1,'''' as other2 from #SDB..t_sys_operator ')
GO
if #TV = 'hbyjtv8'
	if not exists(select top 1 1 from t_sys_operator with(nolock) where oper_id = '1001')
		exec('insert into t_sys_operator (oper_id ,oper_name ,oper_pw,cash_grant ,cashier_status) 
					  values(''1001'',''1001'',''30.-'',''1111111111111111111111'', ''正常''')
else
	if not exists(select top 1 1 from t_rm_cashier with(nolock) where cashier_id = '1001')
		exec('insert into t_rm_cashier(cashier_id,cashier_name,cashier_pw,cashier_grant,cashier_status) 
					  values(''1001'',''1001'',''1001'',''1111111111111111111111'', ''正常''')
					  
go
