您的位置:首页 > 数据库

关于同步 数据同步|数据库同步|SQL同步|

2014-09-30 13:23 295 查看
以T1同步为案例分析

系统1:T1系统

系统2:标书系统

目标: 标书系统为我们的主系统,T1系统是别人的系统

现在需要做同步工作,我们的标书系统需要从 T1中取客户信息来同步

步骤:在T1系统中新建存储过程 p_process

然后新建作业 固定时间自动执行 p_process 存储过程

个人理解:因为数据源在T1系统那边,所以只要T1有数据更新 就可以执行了.还要看谁的系统比较强势,强势方要求自己的系统比较大,所以不能把表结构告诉小系统为了保证自己的系统安全.

以下是存储过程

USE [DLXECRM]

GO

/****** 对象:  StoredProcedure [dbo].[p_process]    脚本日期: 09/30/2014 10:00:28 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

--T1 信息 同步 

ALTER   proc   [dbo].[p_process]   as 

--插入新增 Contacts_T1 不存在的卡号

insert   [CRMSERVER].[DeLiXiTenderSystem2].dbo.[Contacts_T1](card_C) 

select CustCode from  CRM_CB_Sale i 

where not exists( select * from [CRMSERVER].[DeLiXiTenderSystem2].dbo.[Contacts_T1] where card_C=cast(i.CustCode as varchar(50))) 

--更新修改过的数据 根据卡号 修改 联系方式

update   b   

set   card_C=i.CustCode, phone_C=i.CustTele

from   [CRMSERVER].[DeLiXiTenderSystem2].dbo.[Contacts_T1]  b,CRM_CB_Cust i 

where   b.card_C=cast(i.CustCode as varchar(50)) and isnull(b.phone_C,'') <> isnull(i.CustTele,'')

--更新修改过的数据 根据卡号 修改 公司名称 法人代表

update   b   

set    companyName_C=i.SaleComp,responsibilityName_C=i.SalePerM

from   [CRMSERVER].[DeLiXiTenderSystem2].dbo.[Contacts_T1]  b,CRM_CB_Sale i 

where   b.card_C=cast(i.CustCode as varchar(50))  and (isnull(b.companyName_C,'') <> i.SaleComp or isnull(b.responsibilityName_C,'') <> i.SalePerM) 

--删除已经删除的数据 

delete   b   

from   [CRMSERVER].[DeLiXiTenderSystem2].dbo.[Contacts_T1]  b 

where not exists(select * from CRM_CB_Sale where cast(CustCode as varchar(50))=b.card_C) 

--更新字段卡号(卡号为CustSap 不是 CustCode)

update t

set t.card_C = cast(c.CustSap as varchar(50))

from CRM_CB_Cust c,[CRMSERVER].[DeLiXiTenderSystem2].dbo.[Contacts_T1] t

where cast(c.CustCode as varchar(50)) = t.card_C

查看SQL Server代理
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: