Use LiJiang_WeiMeiSiSong select * from TImpMembercard ALTER TABLE TImpMembercard DROP COLUMN FMemo ALTER TABLE TImpMembercard DROP COLUMN FBalance ALTER TABLE TImpMembercard DROP COLUMN FArrear ALTER TABLE TImpMemberCard ADD FCardId BIGINT DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)) NOT NULL ALTER TABLE TImpMemberCard ADD FCardNo AS 储值卡号 ALTER TABLE TImpMemberCard ADD FCardTypeId BIGINT ALTER TABLE TImpMemberCard ADD FCreateDate AS 开卡日期 ALTER TABLE TImpMemberCard ADD FExpiredDate AS 到期日期 ALTER TABLE TImpMemberCard ADD FAcctMemo AS 储值账户备注 ALTER TABLE TImpMemberCard ADD FCompId BIGINT ALTER TABLE TImpMemberCard ADD FMemo AS 储值卡备注 ALTER TABLE TImpMemberCard ADD FArrear AS 储值账户欠款 ALTER TABLE TImpMemberCard ADD FBalance AS 储值账户余额 ALTER TABLE TImpMemberCard ADD FRemainTimes AS 剩余次数 ALTER TABLE TImpMemberCard ADD FMemNo AS 会员编号 ALTER TABLE TImpMember ADD FMemId BIGINT DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)) NOT NULL ALTER TABLE TImpMember ADD FMemNo AS 会员编号 ALTER TABLE TImpMember ADD FName AS 姓名 ALTER TABLE TImpMember ADD FGender AS CASE WHEN 性别 = '男' THEN 1 ELSE 0 END ALTER TABLE TImpMember ADD FMobile AS 手机 exec('ALTER TABLE TImpMember ADD FAddress AS 地址') ALTER TABLE TImpMember ADD FCreateDate AS 加入日期 ALTER TABLE TImpMember ADD FExpiredDate AS 到期日期 ALTER TABLE TImpMember ADD FCompId BIGINT ALTER TABLE TImpMember ADD FPoint AS 积分 ALTER TABLE TImpMember ADD FBirthday AS REPLACE(生日,'0000-','9999-') ALTER TABLE TImpMember ADD FBirthdayType AS CASE WHEN 生日类型 = '农历' THEN 'L' ELSE 'G' END ALTER TABLE TImpMemberCourse ADD FCompId BIGINT ALTER TABLE TImpMember ADD FAddress VARCHAR NOT NULL DEFAULT '' UPDATE A SET A.FCompId = B.FId FROM TImpMember AS A,TCompany AS B WHERE A.门店编号 = B.FNo UPDATE A SET A.FCompId = B.FId FROM TImpMemberCard AS A,TCompany AS B WHERE A.门店编号 = B.FNo UPDATE A SET A.FCompId = B.FId FROM TImpMemberCourse AS A,TCompany AS B WHERE A.门店编号 = B.FNo UPDATE A SET A.FCardTypeId = B.FId FROM TImpMemberCard AS A,TMemberCardType AS B WHERE A.储值卡类别 = B.FNo OR A.储值卡类别 = B.FName INSERT INTO TMember( FMemId, FMemNo, FName, FBriefCode, FTypeId, FCompId, FCreateDate, FGender, FBirthdayType, FBirthday,FTelephone,FMobilePhone,FQQ,FWeChat,FIdCard,FEmail,FAddress,FProId,FCPW,FQPW, FChargeEmpId,FPoint,FRecvConsSMS,FRecvBulkSMS,FMemo,FCustom1,FCustom2,FCustom3,FCustom4,FCustom5) SELECT FMemId AS FMemId, FMemNo AS FMemNo, FName AS FName, dbo.FNGetFirstPinYin(FName), 0 AS FTypeId, FCompId AS FCompId, ISNULL(FCreateDate ,'1900-01-01') AS FCreateDate, FGender AS FGender, FBirthdayType AS FBirthdayType, FBirthday AS FBirthday, '' AS FTelephone, ISNULL(FMobile,'') AS FMobilePhone, '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, FAddress AS FAddress, 0 AS FProId, '' AS FCPW, '' AS FQPW, 0 AS FChargeEmpId, ISNULL( FPoint,0) AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, '' AS FMemo, '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from TImpMember UPDATE A SET A.FMemId = B.FMemId FROM TImpMemberCard AS A,TImpMember AS B WHERE A.FMemNO =B.FMemNO INSERT INTO TMemberCard( FCardId, FCardNo, FCardFaceNo, FTypeId, FValueType, FCompId, FMemId, FState, FCreateDate, FExpiredDate, FTotalTimes, FUsedTimes, FSaleCompId, FSaleBillId, FMemo) SELECT FCardId AS FId, fnewcard AS FNo, FCardNo AS FFaceNo, FCardTypeId AS FTypeId, (SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType, FCompId AS FCompId, FMemId AS FMemId, 1 AS FState, ISNULL(FCreateDate,1900) AS FCreateDate, FExpiredDate, ISNULL(FRemainTimes,0) AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, FMemo AS FMemo FROM TImpMemberCard alter table TImpMemberCard add fnewcard varchar(100) update timpmembercard set fnewcard = fcardno UPDATE TImpMemberCard SET fnewcard = FCARDNo + '_' + cast(fcardid as varchar) where fcardno in( SELECT FCardNo FROM TImpMemberCard GROUP BY FCardNo HAVING SUM(1)>1) SELECT * FROM TImpMemberCard WHERE FCardNo = '13187799188' INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,cast(FBalance as float),cast(FBalance as float),0,FCreateDate,NULL,FAcctMemo FROM TImpMemberCard AS A 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,'',cast(A.FBalance as float),0,cast(A.FBalance as float),0,getdate(),'从Excel中导入' FROM TImpMemberCard AS A DECLARE @NewName VARCHAR(100) SELECT @NewName ='TImpMember_'+ REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR,GETDATE(),20),'-',''),':',''),' ','') EXEC sp_rename 'TImpMember',@NewName SELECT * from TimpMember WHERE FMemNO IN(SELECT FMemNO FROM TMember) SELECT FMemNO FROM TImpMember GROUP BY FMemNO having sum(1) > 1 SELECT * FROM TImpMEMBER WHERE FMemNO = '15770469937' DELETE TImpMember where fmemid = 5234809082376277325 drop table TImpMemberCourse ALTER TABLE TImpMemberCourse ADD FId BIGINT NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FMemId BIGINT NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FCompId BIGINT NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FCourseId BIGINT NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FItemId BIGINT NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FCalcMode AS CASE WHEN 计算方式 ='不计次' THEN 2 ELSE 1 END ALTER TABLE TImpMemberCourse ADD FPurTimes DECIMAL(18,6) NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FPurAmount DECIMAL(18,6) NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FUsedPurTimes DECIMAL(18,6) NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FRemainPurTimes AS CAST(剩余次数 AS DECIMAL(18,6)) ALTER TABLE TImpMemberCourse ADD FFreeTimes DECIMAL(18,6) NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FFreeAmount DECIMAL(18,6) NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FUsedFreeTimes DECIMAL(18,6) NOT NULL DEFAULT 0 ALTER TABLE TImpMemberCourse ADD FRemainFreeTimes AS CAST(剩余赠送次数 AS DECIMAL(18,6)) ALTER TABLE TImpMemberCourse ADD FAdjustPrice AS 核算单价 ALTER TABLE TImpMemberCourse ADD FMemo AS 疗程卡备注 ALTER TABLE TImpMemberCourse ADD FCreateDate AS 购买日期 ALTER TABLE TImpMemberCourse ADD FExpiredDate AS CASE WHEN 到期日期 = '' THEN NULL ELSE 到期日期 END select * from TImpMemberCourse alter table TImpMemberCourse add 计算方式 varchar not Null default '' alter table TImpMemberCourse DROP COLUMN 计算方式 DECLARE @Error VARCHAR(1000); UPDATE TImpMemberCourse SET FId = dbo.FNNewId(); UPDATE A SET A.FMemId = B.FMemId FROM TImpMemberCourse AS A,TMember AS B WHERE A.会员编号 =B.FMemNo DECLARE @MemNo VARCHAR(100) SELECT @MemNo = 会员编号 FROM TImpMemberCourse WHERE ISNULL(FMemId,0) = 0 IF ISNULL(@MemNo,'') != '' BEGIN SELECT @Error = '会员编号' + @MemNo + '不存在'; RAISERROR(@Error,16,1) RETURN END UPDATE A SET A.FCompId = B.FId FROM TImpMemberCourse AS A,TCompany AS B WHERE A.门店编号 =B.FNo DECLARE @CompNo VARCHAR(100) SELECT @CompNo = 门店编号 FROM TImpMemberCourse WHERE ISNULL(FCompId,0) = 0 IF ISNULL(@CompNo,'') != '' BEGIN SELECT @Error = '门店编号' + @CompNo + '不存在'; RAISERROR(@Error,16,1) RETURN END UPDATE A SET A.FCourseId = B.FId, A.FItemId = B.FItemId FROM TImpMemberCourse AS A,TCourse AS B WHERE A.疗程编号 =B.FNo OR A.疗程编号 = B.FName DECLARE @CourseNo VARCHAR(100) SELECT @CourseNo = 疗程编号 FROM TImpMemberCourse WHERE ISNULL(FCourseId,0) = 0 IF ISNULL(@CourseNo,'') != '' BEGIN SELECT @Error = '疗程编号' + @CourseNo + '不存在'; RAISERROR(@Error,16,1) RETURN END --计算购买金额 UPDATE TImpMemberCourse SET FPurTimes = CAST(购买次数 AS DECIMAL(18,6)) UPDATE TImpMemberCourse SET FPurTimes = FRemainPurTimes WHERE FPurTimes < FRemainPurTimes UPDATE TImpMemberCourse SET FUsedPurTimes = 0 FPurTimes - FRemainPurTimes UPDATE TImpMemberCourse SET FPurAmount = (CAST(购买金额 AS DECIMAL(18,6)) / FPurTimes) * FPurTimes WHERE FPurTimes > 0 select * from TImpMemberCourse UPDATE TImpMemberCourse SET FFreeTimes = CAST(赠送次数 AS DECIMAL(18,6)) UPDATE TImpMemberCourse SET FFreeTimes = FRemainFreeTimes WHERE FFreeTimes < FRemainFreeTimes UPDATE TImpMemberCourse SET FUsedFreeTimes = FFreeTimes - FRemainFreeTimes UPDATE TImpMemberCourse SET FFreeAmount = 0 (CAST(赠送金额 AS DECIMAL(18,6)) / FRemainFreeTimes) * FFreeTimes WHERE FRemainFreeTimes > 0 SELECT * FROM TImpMemberCourse UPDATE TImpMemberCourse SET FId = dbo.FNNewId() INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FUsedFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT FId,FMemId,FCourseId,0,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FUsedFreeTimes,FFreeAmount,FCreateDate,FExpiredDate,'DR.Import',0,0,0,FMemo,FCalcMode,ISNULL(FAdjustPrice,0) FROM TImpMemberCourse INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes, FCompId, FBillType,FBizType,FBillId,FBillNo,FBillDetailId) SELECT dbo.FNNewId(),FMemId,FId,0,FCourseId,FTime = getdate(),FPurTimes,FUsedPurTimes,FFreeTimes,FUsedFreeTimes, FCompId, 'DR','Import',0,'',0 FROM TImpMemberCourse SELECT * FROM TImpMember where fpoint > 0