同一数据库MERGE INTO去重插入数据。

sqlserver表结构:


表结构

sql语法:

'''sql_str= u"MERGE INTO T_AGENT_PHONE_DETAIL_copy a " \

u"USING (select '%s' as S_TEL, '%s' as S_MOBILE) b " \

u"ON (a.S_TEL = b.S_TEL and  a.S_MOBILE = b.S_MOBILE) " \

u"WHEN NOT MATCHED THEN " \

u"INSERT " \

u"(I_CITY_ID, S_CITY_NAME, D_IN_TIME, S_DETAIL_URL ," \

u"S_MOBILE ,S_TEL ," \

u"S_COMPANY_NAME, S_CONTACT, I_SITE_ID, S_SITE_NAME, D_COMPANY_CREATE_TIME, I_DATA_TYPE, S_COMPANY_STATUS, S_COMPANY_DESC) VALUES " \

u"(%s, '%s',getdate(),'%s','%s','%s','%s','%s', '%s', '%s', '%s' , '%s', '%s', '%s');" % (

              tel,

mobile,

city_id,

city_name,

detail_url,

mobile,

tel,

company_name,

contact,

self.web_id,

self.web_name,

company_create_time,

data_type,

company_status,

company_desc

)'''

不支持macdown贴上图片方便观看:


你可能感兴趣的:(同一数据库MERGE INTO去重插入数据。)