前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[昆仑会员卡系统]老会员数据导入 从临时表插入会员至member_info_svc表 SQL

[昆仑会员卡系统]老会员数据导入 从临时表插入会员至member_info_svc表 SQL

作者头像
landv
发布2019-08-06 14:47:38
6770
发布2019-08-06 14:47:38
举报
文章被收录于专栏:landv
  • 第一版无UUID版本
代码语言:javascript
复制
从临时表插入会员至member_info_svc表
insert into member_info_svc (
gh_no,chname,sex,birthday,tel,email,title,card_no,membership_type,enroll_date,expiry_date,id_no,
nationality,sub_type,vip_level,member_source,duty_code,language_code,member_department_code,id_type,
linkman_name,address,engname,card_password,insert_user,insert_date)

select card_no,chname,sex,birthday,tel,email,title,card_no,membership_type,enroll_date,expiry_date,id_no,
nationality,sub_type,vip_level,member_source,duty_code,language_code,member_department_code,id_type,
chname,address,engname,'b1e79b6670e5fce34747b8c0a0e684beba9b8550','Shiji','2018-01-11'
from member where  card_no not in (select card_no from member_info_svc);

update member_info_svc set state='N' where insert_date='2018-01-11' and insert_user='Shiji' 


将新导入的会员插入使用者表
insert into member_info_sub(parent_gh_no,sub_name,sex,title,birthday,nationality,address,tel,fax,email,remarks,create_date,position_code,language_code,valid_flag,exchange_flag,filter_flag,
    main_flag,link_code,member_department_code,id_type,id_no,engname,office_tel,mobile,card_sn,card_no)
select gh_no,chname,sex,title,birthday,nationality,address,tel,fax,email,memo,enroll_date,duty_code,language_code,'1','1','0',
    '1','0',member_department_code,id_type,id_no,engname,office_tel,office_tel,card_sn,card_no
from member_info_svc 
where insert_user='Shiji' and insert_date='2018-01-11'
and not exists(select parent_gh_no from member_info_sub where parent_gh_no=member_info_svc.gh_no)

插入变更记录
-------------------------------------------------member_info_log-------------------------------------------------------
 insert into member_card_modify_log(      gh_no,oper_type,oper_date,operator_id,remark  ) 
 select  gh_no,'N',getdate(),'admin','20180111批量导入'
 from member_info_svc 
 where insert_user='Shiji'
and not exists (select gh_no from member_card_modify_log where gh_no=member_info_svc.gh_no)
  • 导入模板样式
代码语言:javascript
复制
card_no    chname    first_name    last_name    title    sex    birthday    email    linkman_tel    tel    office_tel    fax    address    zip    id_type    id_no    language_code    nationality    member_department_code    duty_code    membership_type    vip_level    sub_type    member_source    enroll_date    expiry_date    balance    sendtype_code    memo
960000016    徐新革     gexin    xu    Mr    M    1985-12-31    CRO@SHIJINET.CN    12345678900                        0001    123456789000000000    C    CN    DEA    AA    HZYHZZK    0    FOR    HZ133001GM    2019-07-10    2059-07-10    200    CZ    
  • 插入UUID
代码语言:javascript
复制
insert into member_info_svc(gh_no) values((select replace(NEWID(),'-','')))
  • 获取UUID
代码语言:javascript
复制
select (replace(NEWID(),'-',''))
  •  可生成UUID版本
代码语言:javascript
复制
--从临时表插入会员至member_info_svc表
insert into member_info_svc (
gh_no,chname,sex,birthday,tel,email,title,card_no,membership_type,enroll_date,expiry_date,id_no,
nationality,sub_type,vip_level,member_source,duty_code,language_code,member_department_code,id_type,
linkman_name,address,engname,card_password,insert_user,insert_date)
--生成UUID导入
select (replace(NEWID(),'-','')),chname,sex,birthday,tel,email,title,card_no,membership_type,enroll_date,expiry_date,id_no,
nationality,sub_type,vip_level,member_source,duty_code,language_code,member_department_code,id_type,
chname,address,engname,'b1e79b6670e5fce34747b8c0a0e684beba9b8550','Shiji','2018-01-11'
from member where  card_no not in (select card_no from member_info_svc);

update member_info_svc set state='N' where insert_date='2018-01-11' and insert_user='Shiji' 


--将新导入的会员插入使用者表
insert into member_info_sub(parent_gh_no,sub_name,sex,title,birthday,nationality,address,tel,fax,email,remarks,create_date,position_code,language_code,valid_flag,exchange_flag,filter_flag,
    main_flag,link_code,member_department_code,id_type,id_no,engname,office_tel,mobile,card_sn,card_no)
select gh_no,chname,sex,title,birthday,nationality,address,tel,fax,email,memo,enroll_date,duty_code,language_code,'1','1','0',
    '1','0',member_department_code,id_type,id_no,engname,office_tel,office_tel,card_sn,card_no
from member_info_svc 
where insert_user='Shiji' and insert_date='2018-01-11'
and not exists(select parent_gh_no from member_info_sub where parent_gh_no=member_info_svc.gh_no)

--插入变更记录
-------------------------------------------------member_info_log-------------------------------------------------------
 insert into member_card_modify_log(      gh_no,oper_type,oper_date,operator_id,remark  ) 
 select  gh_no,'N',getdate(),'admin','20180111批量导入'
 from member_info_svc 
 where insert_user='Shiji'
and not exists (select gh_no from member_card_modify_log where gh_no=member_info_svc.gh_no)
代码语言:javascript
复制
--想要将值插入到自动编号(或者说是标识列,IDENTITY)中去,需要设定 

SET IDENTITY_INSERT   member_info_svc ON

SET IDENTITY_INSERT   member_info_svc off
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-08-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档