更新系统档案信息

简介:

/第一步:插入除了手机的商品信息到档案/
declare @sql varchar(max) 
set @sql=(select max(FEntryID) FEntryID from PAEZ_t_xsxxxx where FEntryID>1)
--INSERT INTO PAEZ_t_xsxxxx(F_ENTRYID_JF,fid,fentryid,F_PAEZ_DATE,F_PAEZ_DJLX,F_PAEZ_MD,F_PAEZ_PRICE,F_PAEZ_SPDM,F_PAEZ_SPMC1,F_PAEZ_XSFBILLNO,F_PAEZ_XSJE,F_PAEZ_XSSL,F_PAEZ_qy)
select FEntryID,t16.fid,isnull(@sql,'1001')+ROW_NUMBER() over(order by t0.fbillno) ggg,convert(varchar(10),t0.F_PBKA_DATE,21),t12.fname,t11.fname,FDiscountPrice,t2.FNUMBER,t3.fname,t0.fbillno,case when t0.FBILLTYPEID='57faf492b10d31'
then FSDJAmount else -FSDJAmount end,case when t0.FBILLTYPEID='57faf492b10d31' then FQTY else -FQTY end ,tbtp.fname
From (select fid,F_PBKA_DATE,FBILLTYPEID,FOLDDEPARTMENT,rtrim(ltrim(F_PBKA_PHONE)) F_PBKA_PHONE,FBILLNO From PBKA_t_BillHead where fid>1) t0
left join(select fid,FSDJAmount,FQTY,FMATERIALID,FDiscountPrice,FEntryID from PBKA_t_GoodsDetail where FEntryID>1) t1 on t0.fid=t1.fid
left join (select fid,FLOCALEID from PBKA_t_BillHead_L where fid>1) t10 on t0.fid=t10.fid and t10.FLOCALEID=2052
left join (select FMATERIALID,FNUMBER from t_bd_material where FMATERIALID>1) t2 on t1.FMATERIALID=t2.FMATERIALID
left join (select FMATERIALID,fname From T_BD_MATERIAL_L where FMATERIALID>1 and FLocaleId=2052) t3 on t1.FMATERIALID=t3.FMATERIALID
inner join (select FDEPTID,fname from t_bd_department_l where FDEPTID>1 and FLocaleId=2052) t11 on t0.FOLDDEPARTMENT=t11.FDEPTID
inner join (select FBILLTYPEID,fname from T_BAS_BILLTYPE_L where FLocaleId=2052) t12 on t0.FBILLTYPEID =t12.FBILLTYPEID 
inner join (select FMOBILEPHONE,fid From T_ECC_MEMBER where fid>1) t16 on F_PBKA_PHONE=t16.FMOBILEPHONE
left join (select FCATEGORYID,FMATERIALID From T_BD_MATERIALBASE where FCATEGORYID>1) m on m.FMATERIALID=t2.FMATERIALID
inner join (select FDEPTID,FGROUP from T_BD_DEPARTMENT) tbt on tbt.FDEPTID=t11.FDEPTID
inner join (select FDEPTID,fname from T_BD_DEPARTMENT_L where FLOCALEID=2052) tbtl on tbt.FDEPTID=tbtl.FDEPTID
inner join (select fid,fname from T_BD_DEPARTGROUP_L where FLOCALEID=2052) tbtp on tbt.FGROUP=tbtp.fid 
where (t0.FBILLTYPEID ='580778655b6d7d' or t0.FBILLTYPEID ='57faf492b10d31') and m.FCATEGORYID<>'2092334' and FDiscountPrice<>0
and not exists (select F_ENTRYID_JF from PAEZ_t_xsxxxx where F_ENTRYID_JF<>'' and t1.FEntryID=F_ENTRYID_JF) 
AND (CONVERT(VARCHAR(10),t0.F_PBKA_DATE,21)>=CONVERT(varchar(10), '2018-02-01', 21) AND CONVERT(VARCHAR(10),t0.F_PBKA_DATE,21)<=CONVERT(varchar(10), '2018-02-24', 21) )
--and fbillno='LSD180101393327'
order by fbillno


/第二步:/

---取今天的数据
select (select MAX(FID) FID From T_ECC_MEMBER)+ROW_NUMBER() over(order by fbillno) GGG
,'HY'+substring(t0.fbillno,3,20) xuhao,
F_PBKA_NAME,fbillno,
rtrim(ltrim(F_PBKA_PHONE)) F_PBKA_PHONE,F_PBKA_OLDSALORGID,'1001' FMEMBERTYPEID,'1002' FMEMBERLEVELID,'C' FDOCUMENTSTATUS,
FCREATORID,FCREATEDATE,FCREATORID FCREATORIDs,FCREATEDATE FCREATEDATEs,F_PBKA_CLIENT,F_PBKA_ID 
into #uuu
From (select fbillno,rtrim(ltrim(F_PBKA_PHONE)) F_PBKA_PHONE,F_PBKA_OLDSALORGID,F_PBKA_CLIENT,F_PBKA_ID,FCREATEDATE,FCREATORID,fid from PBKA_t_BillHead where fid>1) t0
left join (select fid,F_PBKA_NAME from PBKA_t_BillHead_L where fid>1) t10 on t0.fid=t10.fid
where F_PBKA_PHONE<>'' and F_PBKA_PHONE not in(select distinct FMOBILEPHONE from T_ECC_MEMBER)
AND CONVERT(VARCHAR(10),FCREATEDATE,21)=CONVERT(varchar(10), getdate(), 21)

------顾客资料表去重电话插入临时表--------
create table #dh (F_PBKA_PHONE varchar(100))
insert into #dh
select distinct rtrim(ltrim(F_PBKA_PHONE)) from #uuu
-------把要插入顾客资料表的信息去重处理----
CREATE TABLE #qc(fbillno varchar(100),F_PBKA_PHONE varchar(100))
insert into #qc
SELECT distinct MAX(fbillno) fbillno,F_PBKA_PHONE FROM #uuu GROUP BY F_PBKA_PHONE ORDER BY 2
---最终要插入的数据
select a.GGG, xuhao,a.fbillno,F_PBKA_NAME,a.F_PBKA_PHONE,F_PBKA_OLDSALORGID,FMEMBERTYPEID,FMEMBERLEVELID,FDOCUMENTSTATUS,FCREATORID,FCREATEDATE,FCREATORID FCREATORIDs,FCREATEDATE FCREATEDATEs,F_PBKA_CLIENT,F_PBKA_ID 
into #uuu1
From #uuu a
inner join #qc b on a.FBILLNO=b.fbillno and a.F_PBKA_PHONE=b.F_PBKA_PHONE

select F_PBKA_NAME,GGG,xuhao,F_PBKA_PHONE,F_PBKA_OLDSALORGID,FMEMBERTYPEID,FMEMBERLEVELID,FDOCUMENTSTATUS,FCREATORID,FCREATEDATE,FCREATORID FCREATORIDs,FCREATEDATE FCREATEDATEs,F_PBKA_CLIENT,F_PBKA_ID 
into #uuu2 
FROM #uuu1
where F_PBKA_PHONE not in(select distinct FMOBILEPHONE from T_ECC_MEMBER)

---判断档案是否存在,插入主表
insert into T_ECC_MEMBER
(FID,FNUMBER ,FMOBILEPHONE ,FSOURCESTOREID ,FMEMBERTYPEID ,FMEMBERLEVELID ,FDOCUMENTSTATUS,FCREATORID ,FCREATEDATE ,FAPPROVERID ,FAPPROVEDATE,FSourceCustId,FFORBIDSTATUS,F_PAEZ_UPDATE,FCardNo,FCardType )
select GGG,xuhao,F_PBKA_PHONE,F_PBKA_OLDSALORGID,FMEMBERTYPEID,FMEMBERLEVELID,FDOCUMENTSTATUS,FCREATORID,FCREATEDATE,FCREATORID FCREATORIDs,FCREATEDATE FCREATEDATEs,F_PBKA_CLIENT,'A','WB',F_PBKA_ID,'2462D139-91B1-4722-AB9A-E87FCDDB63D7' From #uuu2
----end
-----插入从表
insert into T_ECC_MEMBER_L(fpkid,fid,FLOCALEID,FNAME)
select (SELECT MAX(FPKID) FPKID fROM T_ECC_MEMBER_L)+ROW_NUMBER() over(order by FNumber) ,FID,'2052',ISNULL(B.F_PBKA_NAME,'WU') From T_ECC_MEMBER a
INNER JOIN #uuu2 B ON A.FMOBILEPHONE=B.F_PBKA_PHONE
------消费明细更新
declare @sql varchar(max) 
set @sql=(select max(FEntryID) FEntryID from PAEZ_t_xsxxxx where FEntryID>1)
INSERT INTO PAEZ_t_xsxxxx(F_ENTRYID_JF,fid,fentryid,F_PAEZ_DATE,F_PAEZ_DJLX,F_PAEZ_MD,F_PAEZ_PRICE,F_PAEZ_SPDM,F_PAEZ_SPMC1,F_PAEZ_XSFBILLNO,F_PAEZ_XSJE,F_PAEZ_XSSL,F_PAEZ_qy)
select FEntryID,t16.fid,isnull(@sql,'1001')+ROW_NUMBER() over(order by t0.fbillno) ggg,convert(varchar(10),t0.F_PBKA_DATE,21),t12.fname,t11.fname,FDiscountPrice,t2.FNUMBER,t3.fname,t0.fbillno,case when t0.FBILLTYPEID='57faf492b10d31'
then FSDJAmount else -FSDJAmount end,case when t0.FBILLTYPEID='57faf492b10d31' then FQTY else -FQTY end ,tbtp.fname
From (select fid,F_PBKA_DATE,FBILLTYPEID,FOLDDEPARTMENT,rtrim(ltrim(F_PBKA_PHONE)) F_PBKA_PHONE,FBILLNO From PBKA_t_BillHead where fid>1) t0
left join(select fid,FSDJAmount,FQTY,FMATERIALID,FDiscountPrice,FEntryID from PBKA_t_GoodsDetail where FEntryID>1) t1 on t0.fid=t1.fid
left join (select fid,FLOCALEID from PBKA_t_BillHead_L where fid>1) t10 on t0.fid=t10.fid and t10.FLOCALEID=2052
left join (select FMATERIALID,FNUMBER from t_bd_material where FMATERIALID>1) t2 on t1.FMATERIALID=t2.FMATERIALID
left join (select FMATERIALID,fname From T_BD_MATERIAL_L where FMATERIALID>1 and FLocaleId=2052) t3 on t1.FMATERIALID=t3.FMATERIALID
inner join (select FDEPTID,fname from t_bd_department_l where FDEPTID>1 and FLocaleId=2052) t11 on t0.FOLDDEPARTMENT=t11.FDEPTID
inner join (select FBILLTYPEID,fname from T_BAS_BILLTYPE_L where FLocaleId=2052) t12 on t0.FBILLTYPEID =t12.FBILLTYPEID 
inner join (select FMOBILEPHONE,fid From T_ECC_MEMBER where fid>1) t16 on F_PBKA_PHONE=t16.FMOBILEPHONE
left join (select FCATEGORYID,FMATERIALID From T_BD_MATERIALBASE where FCATEGORYID>1) m on m.FMATERIALID=t2.FMATERIALID
inner join (select FDEPTID,FGROUP from T_BD_DEPARTMENT) tbt on tbt.FDEPTID=t11.FDEPTID
inner join (select FDEPTID,fname from T_BD_DEPARTMENT_L where FLOCALEID=2052) tbtl on tbt.FDEPTID=tbtl.FDEPTID
inner join (select fid,fname from T_BD_DEPARTGROUP_L where FLOCALEID=2052) tbtp on tbt.FGROUP=tbtp.fid 
where (t0.FBILLTYPEID ='580778655b6d7d' or t0.FBILLTYPEID ='57faf492b10d31') and FDiscountPrice<>0
and not exists (select F_ENTRYID_JF from PAEZ_t_xsxxxx where F_ENTRYID_JF<>'' and t1.FEntryID=F_ENTRYID_JF) 
AND CONVERT(VARCHAR(10),t0.F_PBKA_DATE,21)=CONVERT(varchar(10),GETDATE(), 21) 
order by fbillno














本文转自51GT51CTO博客,原文链接:http://blog.51cto.com/yataigp/2072558,如需转载请自行联系原作者


相关文章
|
6月前
|
编译器
文件\学生信息录入
文件\学生信息录入
40 3
|
6月前
|
存储 Linux
深入探索Linux命令:`chfn` - 修改用户指纹信息
`chfn`命令在Linux中用于修改用户的指纹信息,包括全名、办公室号码和电话等。用户可运行`chfn`无参数来修改自身信息,或以`sudo chfn username`修改其他用户信息。要查看指纹信息,可使用`finger`命令。指纹信息在服务器管理、系统日志记录和旧版终端界面中仍有其价值。
|
Android开发
Android系统开发中产品信息文件说明
Android系统开发中产品信息文件说明
124 1
|
Shell Perl
显示系统一些基本信息
显示信息如下: 系统版本 系统内核 虚拟平台 主机名 ip地址 开机信息有没有报错,有的话输出到屏幕
68 1
|
安全 Java Windows
不可或缺的BCUninstaller:全面显示软件信息、批量垃圾删除、强制卸载程序……
不可或缺的BCUninstaller:全面显示软件信息、批量垃圾删除、强制卸载程序……
170 0
|
机器学习/深度学习 人工智能 算法
基于PaddleX的可疑人员电子图片信息检查
基于PaddleX的可疑人员电子图片信息检查
117 0
基于PaddleX的可疑人员电子图片信息检查
|
Oracle 关系型数据库
10G自动收集统计信息修改
10G自动收集统计信息修改
116 0
10G自动收集统计信息修改
|
存储 开发框架 .NET
锅炉系统电子记录管理与查询(一)
为充分利用企业网络资源,加强特种设备管理,以ASP(Active Server Pages)动态网页程序设计为背景,记录锅炉系统的维护、检修、检验等相关信息,实现锅炉系统设备记录数据的新增、修改、删除、查询功能。为网络化管理锅炉系统电子记录管理查询提供了极大方便。