use DeZhou_Venus SELECT * FROM TImpMember where 生日 is not null sp_rename 'TImpMember.储值卡备注','卡备注' sp_rename 'TImpMember.作废日期','到期日期' alter table TImpMember add 账户欠款 int alter table TImpMember add 账户备注 int alter table TImpMember add FBirthdayType AS 生日类型 update TImpMember set 门店编号 = '001' update TImpMember set 生日 = null where 生日 = '' alter table TImpMember drop column 卡备注 UPDATE TImpMember SET 剩余次数 = 0 UPDATE TImpMember SET 账户欠款 = 0 UPDATE TImpMember SET 卡备注 = '' WHERE 卡备注 IS NULL UPDATE TImpMember SET 账户备注 = '' WHERE 账户备注 IS NULL UPDATE TImpMember SET 卡备注 = '' WHERE 卡备注 ='.' INSERT INTO TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FCardFeeAmt,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue,FPaySmsFee,FTimeCard,FValidityPeriod,FValidityPeriodUnit,FExpiredDate,FDefaultMemo,FCreateTime,FAllowSale,FAllowRchg,FDeptId,FEnabled,FOrder) SELECT FId =dbo.FNNewId(), ch_member_typeno,vch_member_typename as name,1,FMaterial = 2,0,FCardFeeAmt = 0,FAcctId = 3,FDeposit = 0,FAcctId2 = 0,FDeposit2 = 0 ,FAcctId3 = 0,FDeposit3 = 0, FTimes = 0,FAlertBalance = 0,FMinRchgAmt = 0,FSalePointMode = 0,FSalePointValue = 0 ,FRchgPointMode = 0,FRchgPointValue = 0,FPaySmsFee = 0,FTimeCard = 0,FValidityPeriod = 100,FValidityPeriodUnit = 1, FExpiredDate = NULL,FDefaultMemo = '',FCreateTime = GETDATE(),1,1,FDeptId = 0,FEnabled =1,FOrder = 1 FROM dezhou_venus_old..mr_m_member_type EXEC PImportMemberData_Init EXEC PImportMemberData_Exec SELECT * FROM TMemberPointHist INSERT TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) select dbo.FNNewId(),A.FMemId,A.FCardId,3,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'从老系统中导入' FROM TImpMember_1 AS A DELETE TMemberCardAcctHist WHERE FCardId UPDATE TImpMember SET 到期日期 = '9000-1-1' WHERE 到期日期 IS NULL SELECT * FROM TImpMember UPDATE TMember SET FPoint = 0 WHERE FMemId IN(SELECT FMemId FROM TImpMember) sp_rename 'TImpMember','TImpMember_1' use dezhou_venus_old SELECT mr_m_member.vch_memberno , mr_m_member.vch_membername , mr_m_member.ch_member_typeno , mr_m_member.dt_birthday , mr_m_member.vch_linktel , mr_m_member.vch_address , mr_m_member.dt_limit , mr_m_member.ch_state , mr_m_member.vch_operID , mr_m_member.dt_operdate , "flag" = '', mr_m_member.num_limit , mr_m_member.vch_ID , mr_m_member.vch_memo , mr_m_member.ch_hqflag , mr_m_member.vch_handset FROM mr_m_member WHERE ( mr_m_member.ch_hqflag = 'N' ) SELECT mr_m_member.vch_memberno 会员卡号, mr_m_member.vch_membername 姓名, mr_m_member.ch_member_typeno 储值卡类别 , mr_m_member.dt_birthday 生日, ISNULL(mr_m_member.vch_linktel,'') vch_linktel , ISNULL(mr_m_member.vch_handset,'') 手机 , mr_m_member.vch_address , mr_m_member.dt_limit 到期日期, mr_m_member.ch_state as 状态, mr_m_member.vch_operID , mr_m_member.dt_operdate 开卡日期, mr_m_member.num_limit AS num_limit, mr_m_member.vch_ID , isnull( mr_m_member.vch_memo ,'') AS 卡备注, mr_m_member.ch_hqflag , ISNULL(mr_m_member.vch_sex,'女') 性别, mr_m_member.vch_nation , mr_m_member.vch_profession , mr_m_member.vch_vehicle , mr_m_member.vch_email , mr_m_member.vch_commend INTO TImpMember FROM dezhou_venus_old..mr_m_member WHERE 1=1 AND vch_memberno NOT IN(SELECT FMemNO from TMember) AND mr_m_member.ch_hqflag = 'N' alter table TImpMember add 门店编号 VARCHAR(100) alter table TImpMember add 账户欠款 int alter table TImpMember add 剩余次数 int alter table TImpMember add 账户备注 varchar alter table TImpMember add 生日类型 varchar default 'G' alter table TImpMember add 账户余额 decimal(18,6) not null default 0,积分 decimal(18,6) not null default 0 UPDATE A SET A.账户余额 = ISNULL(I.FAmount,0) - ISNULL(O.FAmount,0) FROM TImpMember AS A LEFT JOIN (Select vch_memberno,IsNull ( Sum ( num_amount ) , 0 ) AS FAmount from dezhou_venus_old..mr_m_pay where ch_paymodeno ='02' and ch_hqflag ='N' GROUP BY vch_memberno) AS O ON O.vch_memberno = A.会员卡号 LEFT JOIN (Select vch_memberno, IsNull ( sum ( num_deposit ) , 0 )as FAmount from dezhou_venus_old..mr_m_deposit where ch_hqflag ='N' GROUP BY vch_memberno ) AS I ON I.vch_memberno = A.会员卡号 SELECT * FROM TImpMember where 会员卡号 = '20031' DELETE TMemberCardAcctHist WHERE FBillType = 'DR' AND FCardId IN(SELECT FCardId FROM TImpMember_1) SELECT B.vch_memberno, num_amount FROM dezhou_venus_old..mr_m_pay AS B WHERE 1=1 and ch_paymodeno ='02' and ch_hqflag ='N' AND vch_memberno = '20031' UPDATE A SET A.积分 = B.FBalance FROM TImpMember AS A, ( SELECT B.vch_memberno,SUM(num_marking) AS FBalance FROM dezhou_venus_old..mr_m_marking AS B WHERE 1=1 and ch_hqflag ='N' GROUP BY vch_memberno ) AS B WHERE A.会员卡号 = B.vch_memberno SELECT * FROM TImpMember WHERE FMemNo = '20031' WHERE ( mr_m_member.vch_memberno = '110005' ) and ( mr_m_member.ch_hqflag = 'N' ) SELECT * FROM dezhou_venus_old..mr_m_member WHERE ch_state != 1 Select IsNull ( Sum ( num_amount ) , 0 ) from dezhou_venus_old..mr_m_pay where vch_memberno ='20031' and ch_paymodeno ='02' and ch_hqflag ='N' Select IsNull ( sum ( num_deposit ) , 0 ) from dezhou_venus_old..mr_m_deposit where vch_memberno ='20031' and ch_hqflag ='N' SELECT 260.00 - 186.00 Select IsNull ( max ( int_id ) , 0 ) from mr_m_deposit where vch_memberno ='20002' Select IsNull ( sum ( num_marking ) , 0 ) from dezhou_venus_old..mr_m_marking where vch_memberno ='20031' and ch_hqflag ='N' SELECT * FROM mr_m_pay WHERE ch_hqflag != 'N' Select IsNull ( Sum ( num_amount ) , 0 ) from mr_m_deposit_arrearage where vch_memberno ='20002' Select IsNull ( Sum ( num_amount ) , 0 ) from mr_m_pay where vch_memberno ='20002' and ch_paymodeno ='02' Select vch_member_typename , ch_attribute from mr_m_member_type where ch_member_typeno ='A1' SELECT * FROM mr_m_member_type SELECT * FROM mr_m_member WHERE ch_member_typeno = 'A2' SELECT * FROM ( SELECT FCardId,FAcctId,FBalance FROM TMemberCardAccount ) AS T1, ( SELECT FCardId,FAcctId, SUM(FInAmount) - SUM(FOutAmount) AS FBalance FROM TMemberCardAcctHist GROUP BY FCardId,FAcctId ) AS T2 WHERE T1.FCardId = T2.FCardId AND T1.FAcctId = T2.FAcctId AND T2.FBalance != T1.FBalance AND T1.FCardId IN(SELECT FCardId FROM TImpMember) UPDATE A SET A.FBalance = B.FBalance FROM TMemberCardAccount AS A, ( SELECT FCardId,FAcctId, SUM(FInAmount) - SUM(FOutAmount) AS FBalance FROM TMemberCardAcctHist GROUP BY FCardId,FAcctId ) AS B WHERE A.FCardId = B.FCardId AND A.FAcctId = B.FAcctId AND A.FCardId IN(SELECT FCardId FROM TImpMember)