use taiyuan_yihao drop table TImpMember drop table TImpMemberCard SELECT COUNT(1) FROM TImpMemberCard SELECT COUNT(1) FROM TImpMember SELECT * FROM TImpMember SELECT * FROM TImpMemberCard --门店 SELECT * FROM TImpCompany ALTER TABLE TImpCompany ADD FCompId BIGINT ALTER TABLE TImpCompany ADD FCompNo VARCHAR(20) UPDATE A SET A.FCompId = B.FId, A.FCompNo = B.FNo FROM TIMpCompany AS A,TCompany AS B WHERE ShopId = '74803' AND B.FNo = '003' UPDATE TImpMember SET FCom --UPDATE TImpCompany SET FCompId = dbo.FNCompId('002') WHERE ShopId = '74802' --UPDATE TImpCompany SET FCompId = dbo.FNCompId('003') WHERE ShopId = '74803' UPDATE TImpMember SET 消费次数 = 当前积分,当前积分 = 最后消费日,最后消费日= 卡账户信息 where 当前积分 like '%次%' SELECT * FROM TImpMember where 当前积分 like '%次%' SELECT MemId,SUM(1) FROM TImpMemberCard GROUP BY MemId HAVING(SUM(1)) > 1 DROP TABLE TImpCardType CREATE TABLE TImpCardType ( FId BIGINT, FNo VARCHAR(50), FName VARCHAR(50), FType VARCHAR(50), FValueType INT ) ALTER TABLE TImpMemberCard ADD FCardTypeName VARCHAR(100) ALTER TABLE TImpMember ADD FMemId BIGINT ALTER TABLE TImpMemberCard ADD FMemId BIGINT ALTER TABLE TImpMemberCard ADD FCardNo VARCHAR(50) ALTER TABLE TImpMember ADD FMemNo VARCHAR(50) ALTER TABLE TImpMember ADD FName VARCHAR(50) ALTER TABLE TImpMember ADD FGender INT ALTER TABLE TImpMember ADD FMobile VARCHAR(50) ALTER TABLE TImpMember ADD FCreateDate DATETIME ALTER TABLE TImpMemberCard ADD FCardTypeId BIGINT ALTER TABLE TImpMemberCard ADD FCourseId BIGINT ALTER TABLE TImpMemberCard ADD FBalance DECIMAL(18,6) ALTER TABLE TImpMemberCard ADD FBalance2 DECIMAL(18,6) ALTER TABLE TImpMemberCard ADD FRemainTimes INT ALTER TABLE TImpMemberCard ADD FPurTimes INT ALTER TABLE TImpMemberCard ADD FPurAmount DECIMAL(18,6) ALTER TABLE TImpMemberCard ADD FItemId BIGINT ALTER TABLE TImpMemberCard ADD FCreateDate DATETIME ALTER TABLE TImpMemberCard ADD FExpiredDate DATETIME ALTER TABLE TImpMember ADD FCompId BIGINT ALTER TABLE TImpMemberCard ADD FCompId BIGINT ALTER TABLE TImpMemberCard ADD FCardId BIGINT ALTER TABLE TImpMember ADD FArrear DECIMAL(18,6) ALTER TABLE TImpMember ADD FPoint DECIMAL(18,6) ALTER TABLE TImpMember ADD FBirthday DATETIME ALTER TABLE TImpMember ADD FBirthdayType CHAR ALTER TABLE TImpMember ADD FCustom1 VARCHAR(100) ALTER TABLE TImpMember ADD FPointText VARCHAR(100) DELETE TImpMemberCard SELECT COUNT(1) FROM TImpMemberCard SELECT COUNT(1) FROM TImpMemberCard ALTER TABLE TImpMemberCoursePack ADD FCardTypeId BIGINT ALTER TABLE TImpMemberCoursePack ADD FItemId BIGINT ALTER TABLE TImpMemberCoursePack ADD FRemainTimes INT ALTER TABLE TImpMemberCoursePack ADD FPurTimes INT ALTER TABLE TImpMemberCoursePack ADD FUsedTimes INT ALTER TABLE TImpMemberCoursePack ADD FPurAmount DECIMAL(18,6) ALTER TABLE TImpMemberCoursePack ADD FCreateDate DATETIME ALTER TABLE TImpMemberCoursePack ADD FExpiredDate DATETIME ALTER TABLE TImpMemberCoursePack ADD FCompId BIGINT ALTER TABLE TImpMemberCoursePack ADD FCardId BIGINT ALTER TABLE TImpMemberCoursePack ADD FMemId BIGINT ALTER TABLE TImpMemberCoursePack ADD FMemo VARCHAR(1000) ALTER TABLE TImpMemberYearCard ADD FCardTypeId BIGINT ALTER TABLE TImpMemberYearCard ADD FItemId BIGINT ALTER TABLE TImpMemberYearCard ADD FRemainTimes INT ALTER TABLE TImpMemberYearCard ADD FPurTimes INT ALTER TABLE TImpMemberYearCard ADD FUsedTimes INT ALTER TABLE TImpMemberYearCard ADD FPurAmount DECIMAL(18,6) ALTER TABLE TImpMemberYearCard ADD FCreateDate DATETIME ALTER TABLE TImpMemberYearCard ADD FExpiredDate DATETIME ALTER TABLE TImpMemberYearCard ADD FCompId BIGINT ALTER TABLE TImpMemberYearCard ADD FCardId BIGINT ALTER TABLE TImpMemberYearCard ADD FMemId BIGINT ALTER TABLE TImpMemberYearCard ADD FMemo VARCHAR(1000) ALTER TABLE TImpMemberYearCard ADD FItemName VARCHAR(50) ALTER TABLE TImpMemberYearCard ADD FCalcMode INT --添加索引 alter table TImpMemberCard alter column cardId VARCHAR(50) alter table TImpMember alter column memId VARCHAR(50) CREATE unique CLUSTERED INDEX IX_TImpMemberCard ON TImpMemberCard (cardId) CREATE unique CLUSTERED INDEX IX_TImpMember ON TImpMember (memId) SELECT * FROM TImpMemberCard WHERE FMemo IS NULL UPDATE TImpMemberCard SET FMemo = '' WHERE FMemo IS NULL UPDATE TImpMember SET FMemo = '' WHERE FMemo IS NULL --初始化卡类别 UPDATE TImpMemberCard SET FCardTYpeName = 卡名称 + '[' + 折扣 + '折]' DELETE TImpCardType INSERT TImpCardType(FId,FNo,FName,FValueType) SELECT dbo.FNNewId() AS FId,FNo,FName,FValueType FROM ( SELECT FCardTYpeName AS FNo, FCardTYpeName AS FName ,CASE WHEN 卡类型 = '计次消费' THEN 3 ELSE 1 END AS FValueType FROM TImpMemberCard WHERE 卡类型 IS NOT NULL AND 卡号 IS NOT NULL GROUP BY FCardTYpeName ,卡类型) AS A GROUP BY FNo,FName,FValueType --会员ID UPDATE TImpMember SET FMemId = MemId UPDATE TImpMemberCard SET FMemId = MemId SELECT * FROM TImpMemberCard --开卡日期 UPDATE TImpMember SET FCreateDate = 注册日期 UPDATE A SET A.FCreateDate = B.FCreateDate FROM TImpMemberCard AS A,TImpMember AS B WHERE A.MemId = B.MemId ALTER DATABASE TUser ADD FILEGROUP cache_mod CONTAINS MEMORY_OPTIMIZED_DATA -- Important! In the path below, you specify a folder, not a file. ALTER DATABASE TUser ADD FILE (name='cache_mod', filename='c:\Program Files\Microsoft Sql Server\MSSQL12.MSSQLSERVER\MSSQL\DATA') TO FILEGROUP cache_mod ALTER DATABASE TUser SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT=ON UPDATE TImpMemberCard SET FExpiredDate = 失效日期 WHERE 失效日期 != '0' AND 失效日期 != '' AND LEN(失效日期) = 10 UPDATE TImpMemberCard SET FExpiredDate = DATEADD(YEAR,100,FCreateDate) WHERE FExpiredDate = '1900-01-01' OR FExpiredDate IS NULL --处理卡号 UPDATE TImpMemberCard SET FCardNo = 卡号 --处理重复卡号 DROP TABLE #Card SELECT FCardNo into #Card FROM TImpMemberCard GROUP BY FCardNo HAVING(SUM(1)) > 1 ALTER TABLE TImpMemberCard ADD FSeq INT IDENTITY ALTER TABLE TImpMemberCard ADD FIndex INT UPDATE A SET A.FIndex = 1+(SELECT COUNT(1) FROM TImpMemberCard AS B WHERE A.FCardNo = B.FCardNo AND (A.FCreateDate > B.FCreateDate OR (A.FCreateDate = B.FCreateDate AND (A.FSeq > B.FSeq) ))) FROM TImpMemberCard AS A SELECT * FROM TImpMemberCard WHERE FCardNo IN(SELECT FCardNO FROM #Card) AND FIndex > 0 order by FCardNo --删除完全一样的 DELETE A FROM TImpMemberCard AS A, ( SELECT MemId,CardId,MIN(FSeq) AS FSeq FROM TImpMemberCard WHERE FCardNO iN(SELECT FCardNo FROM #Card) GROUP BY MemId,CardId HAVING(SUM(1)>1) ) AS B WHERE A.MemId = B.MemId AND A.CardId = B.CardId AND A.FSeq = B.FSeq UPDATE TImpMemberCard SET FCardNo = FCardNo + '.' + CAST(FIndex AS VARCHAR) WHERE FCardNo IN( SELECT FCardNo FROM #Card) /* UPDATE A SET A.FCardNo = B.FCardNo FROM TImpMemberCard AS A,TImpMemberCard AS B WHERE A.FMemId = B.FMemId AND A.FIndex > 1 AND B.FIndex = 1 */ SELECT FCardNo,SUM(1) AS Cnt FROM TImpMemberCard GROUP BY FCardNo ORDER BY SUM(1) DESC SELECT FMemNo,FMobile,SUM(1) AS Cnt FROM TImpMember GROUP BY FMemNo ,FMobile ORDER BY SUM(1) DESC SELECT FMemNo,SUM(1) AS Cnt FROM TImpMember WHERE FMemId IN(SELECT FMemId FROM TImpMemberCard) GROUP BY FMemNo ORDER BY SUM(1) DESC UPDATE TImpMemberCard SET FCardId = CardId UPDATE TImpMemberCard SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL --会员编号 UPDATE A SET A.FMemNo = B.FCardNo FROM TImpMember AS A,TImpMemberCard AS B WHERE A.MemId = B.MemId UPDATE TImpMember SET FMemNo = 手机号 WHERE ISNULL(FMemNo,'') = '' UPDATE TImpMember SET FName = 姓名 UPDATE TImpMember SET FMobile = 手机号 UPDATE TImpMember SET FGender = CASE WHEN 性别 = '男' THEN 1 ELSE '0' END UPDATE TImpMember SET FMobile = '' WHERE FMobile IN( '0' , '00' , '000' , '0000' , '00000' , '000000' , '0000000' , '00000000' , '000000000' , '0000000000' , '00000000000') UPDATE TImpMember SET FPointText = replace(replace(replace(replace(当前积分,'分',''),char(10),''),char(13),''),' ','') UPDATE TImpMember SET FPoint = CAST(FPointText AS FLOAT) SELECT * FROM TImpMember where 当前积分 like '%次%' --门店 UPDATE TImpMember SET FCompId = dbo.FNCompId('001') UPDATE TImpMemberCard SET FCompId = dbo.FNCompId('002') SELECT MemId,ShopId FROM TImpMemberCard WHERE 1=1 GROUP BY MemId,ShopId SELECT MemId,(SELECT TOP 1 ShopId FROM TImpMemberCard ) SELECT * FROM TImpMember WHERE FCardTypeID IS NULL SELECT * FROM TImpMemberCard UPDATE A SET A.FCardTypeId = B.FId FROM TImpMemberCard AS A,TImpCardType AS B WHERE A.FCardTypeName= B.FName SELECT * FROM TImpMemberCard SELECT * FROM TImpCardType UPDATE TImpMember SET FBirthdayType = 'G' UPDATE TImpMember SET FBirthdayType = 'L' WHERE 生日 LIKE '%农历%' UPDATE TImpMember SET FBirthday = 生日 WHERE 生日 != '' --门店 -- 余额 SELECT * FROM TImpMemberCard WHERE CardId NOT IN(SELECT CardId FROM TImpTransHist) SELECT FRemainTimes FROM TImpMemberCard WHERE FRemainTimes > 0 UPDATE TImpMemberCard SET FRemainTimes = REPLACE(SUBSTRING(卡内余额,CHARINDEX('余:',卡内余额) + 2,LEN(卡内余额)),'次','') FROM TImpMember WHERE 卡类型 = '计次消费' SELECT * FROM TImpMemberCard WHERE 卡类型 not in( '计次消费') UPDATE TImpMemberCard SET FBalance = CAST( REPLACE( REPLACE(REPLACE(REPLACE(LEFT(卡内余额,CHARINDEX('元',卡内余额)),'元',''),' ','') ,char(10),''),' ','') AS float) WHERE 卡内余额 IS NOT NULL SELECT 赠送余额 FROM TImpMemberCard --处理赠送余额 ALTER TABLE TImpMemberCard ADD FBalance2Text VARCHAR(10) UPDATE TImpMemberCard SET FBalance2Text = CAST(REPLACE( REPLACE(REPLACE(REPLACE(LEFT(赠送余额,CHARINDEX('元',赠送余额) + 3),'元',''),' ','') ,char(10),''),' ','') AS varchar) UPDATE TImpMemberCard SET FBalance2 = CAST(REPLACE( REPLACE(REPLACE(REPLACE(LEFT(赠送余额,CHARINDEX('元',赠送余额) + 3),'元',''),' ','') ,char(10),''),' ','') AS float) --WHERE 赠送余额 NOT LIKE '%套餐%' ---------- SELECT SUM(CAST(REPLACE( REPLACE(REPLACE(REPLACE(LEFT(赠送余额,CHARINDEX('元',赠送余额) + 3),'元',''),' ','') ,char(10),''),' ','') AS float) ) FROM TImpMemberCard -- delete TMemberCardType WHERE FId > 100 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 ,FNo,FName,FValueType,2,0,0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 FROM TImpCardType SELECT * FROM TImpMemberCard WHERE FCardTypeId NOT IN(SELECT FId FROM TMemberCardType) ORDER BY FNo UPDATE TMemberCardType SET FAllowRchg = 1 WHERE FId IN(SELECT FId FROM TImpCardType) UPDATE TMemberCardType SET FAllowSale = 1 WHERE FId IN(SELECT FId FROM TImpCardType) UPDATE TMemberCardType SET FEnabled = 1 WHERE FId IN(SELECT FId FROM TImpCardType) UPDATE TMemberCardType SET FValidityPeriod = 100 WHERE FId IN(SELECT FId FROM TImpCardType) UPDATE TMemberCardType SET FValidityPerioduNIT = 1 WHERE FId IN(SELECT FId FROM TImpCardType) UPDATE TMemberCardType SET FExpiredDate = null WHERE FId IN(SELECT FId FROM TImpCardType) UPDATE TMemberCardType SET FDeposit = 0,FDefaultMemo = '' WHERE FId IN(SELECT FId FROM TImpCardType) INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled) SELECT dbo.FNNewId(),C.FId,I.FId,FAllowSale,FAllowRchg,FEnabled FROM TMemberCardType AS I,TCompany AS C WHERE I. FId IN(SELECT FId FROM TImpCardType) AND C.FId = dbo.FNCompId('001') AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId) UPDATE TMemberCardType SET FMaterial = 2 UPDATE A SET A.FValueType = 3 FROM TMemberCardType AS A,TImpCardType AS B WHERE A.FId = B.FId --套餐 SELECT dbo.FNNewId() AS FId,项目 AS FName,项目 AS FNo INTO TImpItem FROM TImpCourse GROUP BY 项目 SELECT * FROM TImpCourse ALTER TABLE TImpCourse ADD FId BIGINT,FItemId BIGINT,FTimes INT, FPrice DECIMAL(18,6),FAmount DECIMAL(18,6),FValidityPeriod INT ALTER TABLE TImpCourse ADD FName VARCHAR(100) ALTER TABLE TImpCourse ADD FCalcMode INT SELECT * FROM TImpCourse UPDATE TImpCourse SET FValidityPeriod = 0 UPDATE TImpCourse SET FValidityPeriod = 1 WHERE 期限 = '365天' UPDATE TImpCourse SET FId = dbo.FNNewId() UPDATE TImpCourse SET FName = 项目 + '[' + 次数 + ']' + '[' + 金额 +']' UPDATE TImpCourse SET FPrice = 单次消耗业绩 UPDATE TImpCourse SET FAMount = 金额 UPDATE TImpCourse SET FTimes = 次数 WHERE 次数 != '不限次' UPDATE TImpCourse SET FCalcMode = 1 UPDATE TImpCourse SET FCalcMode = 2 WHERE 次数 != '不限次' UPDATE A SET A.FItemId = B.FId FROM TImpCourse AS A,TImpItem AS B WHERE A.FName = B.FName SELECT * FROM TImpMemberYearCard SELECT * FROM TImpMemberCoursePack --处理年卡名称 UPDATE TImpMemberYearCard SET FItemName = SUBSTRING(年卡项目名称, CHARINDEX(')',年卡项目名称) + 1,LEN(年卡项目名称)) DROP TABLE TImpItem SELECT dbo.FNNewId() AS FId,dbo.FNNewId() AS FCourseId,FNo,FName INTO TImpItem FROM ( select 'SC_' + 项目名称 AS FNo, 项目名称 AS FName from TImpMemberCoursePack GROUP BY 项目名称 /* UNION ALL select 'SC_' + FItemName AS FNo, FItemName AS FName FROM TImpMemberYearCard GROUP BY FItemName */ ) AS A GROUP BY FNo,FName DELETE TItem WHERE FId IN(SELECT FId FROM TImpItem_2) INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking) SELECT FId,FNo,FName,FName,FName,0,dbo.FNGetFirstPinYin(FName),'''',1,1,1,'''','''','''',1,0,0,0,0,0,0,0,1 FROM TImpItem ORDER BY FNo INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode) SELECT FId AS FId, A.FName + '', A.FName AS FName, '' AS FBriefCode, A.FItemId AS FItemId, 0 AS FPackId, 1 AS FSequence, 0,--(SELECT TOP 1 FId FROM TBasicType WHERE FKey = 'CourseType') AS FTypeId, ISNULL(FTimes,0) AS FTimes, 0 AS FFreeTimes, 0 AS FDurable, 1 AS FValidityPeriodUnit, FValidityPeriod AS FValidityPeriod, getdate() AS FCreateDate, NULL AS FExpiredDate, '' AS FDescription, 1 AS FEnabled, FPrice AS FPrice, FAMount AS FAmount, 1 AS FCalcMode FROM TImpCourse AS A INSERT TItemSub(FId,FCompId,FItemId,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking,FEnabled) SELECT dbo.FNNewId(),C.FId,I.FId,I.FPrice,I.FVipPrice,I.FTime,I.FDctId,I.FPointMode,I.FPointValue,I.FDeptId,I.FAllowBooking,I.FEnabled FROM TItem AS I,TCompany AS C WHERE I.FId != 0 AND C.FId != 0 AND C.FNo IN('001') AND NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId) AND I.FId IN(SELECT FId FROM TImpItem) SELECT * FROM TImpMemberCoursePack UPDATE TImpMemberCoursePack SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL UPDATE TImpMemberCoursePack SET FExpiredDate = NULL UPDATE TImpMemberCoursePack SET FExpiredDate = 失效日期 WHERE 失效日期 != '' UPDATE TImpMemberCoursePack SET FMemo = '' UPDATE A SET A.FItemId = B.FItemId, A.FCardTypeId = B.FId FROM TImpMemberCoursePack AS A,TImpCourse AS B WHERE A.项目名称 = B.name AND REPLACE(总次数,'次','') = REPLACE(B.次数,'次','') UPDATE A SET A.FItemId = B.FItemId, A.FCardTypeId = B.FId FROM TImpMemberCoursePack AS A,TCourse AS B WHERE A.项目名称 = B.Fname AND A.FItemId = 0 SELECT * FROM TImpMemberCoursePack WHERE replace(项目名称,' ','') NOT IN( SELECT name FROM TImpCourse AS B ) ALTER TABLE TImpCourse ADD name VARCHAR(100) UPDATE TImpCourse SET 项目 = replace(项目,' ','') UPDATE TImpCourse SET 项目 = replace(项目,' ','') UPDATE TImpCourse SET name = SUBSTRING(项目,6,LEn(项目) - 5) 疏通 SELECT * FROM TImpCourse SELECT * FROM TImpCourse WHERE 项目 LIKE '%梵古%' SELECT * FROM TImpMemberCoursePack UPDATE TImpMemberCoursePack SET FItemId = 0,FCardTypeId = 0 SELECT * FROM TImpCourse SELECT * FROM TImpMemberCoursePack SELECT * FROM TCourse UPDATE TImpMemberCoursePack SET FRemainTimes = 剩余次数 UPDATE TImpMemberCoursePack SET FPurTimes = REPLACE(总次数,'次','') UPDATE TImpMemberCoursePack SET FPurAmount = 充值总额 UPDATE TImpMemberCoursePack SET FUsedTimes = FPurTimes - FRemainTimes UPDATE A SET A.FCreateDate = B.FCreateDate, A.FMemId = B.FNewMemId FROM TImpMemberCoursePack AS A,TImpMember AS B WHERE A.MemId = B.FMemId UPDATE TImpMemberCoursePack SET FCompId = dbo.FNCompId('001') UPDATE TImpMemberCoursePack SET FMemId = MemId --年卡 UPDATE TImpMemberYearCard SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL UPDATE TImpMemberYearCard SET FExpiredDate = NULL UPDATE TImpMemberYearCard SET FExpiredDate = 失效日期 WHERE 失效日期 != '' UPDATE TImpMemberYearCard SET FMemo = '' --单独处理项目名称 SELECT * FROM TImpMemberYearCard UPDATE A SET A.FItemId = B.FItemId, A.FCardTypeId = B.FId FROM TImpMemberYearCard AS A,TCourse AS B WHERE FItemName = B.FName UPDATE TImpMemberYearCard SET FRemainTimes = 剩余次数 UPDATE TImpMemberYearCard SET FPurTimes = REPLACE(总次数,'次','') UPDATE TImpMemberYearCard SET FPurAmount = 0 UPDATE TImpMemberYearCard SET FUsedTimes = FPurTimes - FRemainTimes UPDATE TImpMemberYearCard SET FCalcMode = 2 UPDATE TImpMemberYearCard SET FCalcMode = 1 WHERE 总次数 > 0 UPDATE A SET A.FCreateDate = B.FCreateDate, A.FMemId = B.FMemId FROM TImpMemberYearCard AS A,TImpMemberCard AS B WHERE A.CardId = B.CardId UPDATE TImpMemberYearCard SET FCompId = dbo.FNCompId('001') UPDATE TImpMember SET FMemNO = 'MH' + FMemNo WHERE FMemNo IN(SELECT FMemNO FROM TMember) UPDATE TImpMemberCard SET FCardNo = 'MH' + FCardNo WHERE FCardNo IN(SELECT FCardNo FROM TMember) --合并 ALTER TABLE TImpMember ADD FNewPoint DECIMAL(18,6) ALTER TABLE TImpMember ADD FNewMemId BIGINT ALTER TABLE TImpMemberCard ADD FNewMemId BIGINT ALTER TABLE TImpMember ADD FMemIndex INT IDENTITY NOT NULL ALTER TABLE TImpMemberCoursePack ADD FNewMemId BIGINT UPDATE TImpMember SET FNewMemId = FMemId UPDATE TImpMember SET FNewPoint = FPoint UPDATE TImpMemberCard SET FNewMemId = FMemId UPDATE TImpMemberCoursePack SET FNewMemId = FMemId UPDATE A SET A.FNewMemId = B.FMemId,A.FNewPoint = B.FNewPoint FROM TImpMember AS A,TImpMember AS B,( SELECT FMobile,FName ,SUM(FPoint) AS FNewPoint,MIN(DATEADD(MINUTE,D.FMemIndex, FCreateDate)) AS FCreateDate,SUM(1) AS FCount FROM TImpMember D WHERE FMobile != '' AND LEN(FMobile) = 11 GROUP BY FMobile,FName HAVING(SUM(1) > 1) ) AS C WHERE C.FCreateDate = DATEADD(MINUTE,B.FMemIndex, b.FCreateDate) AND C.FMobile = B.FMobile AND C.FName = B.FName AND A.FMobile = B.FMobile AND A.FName = B.FName update TIMpMember SET FNewMemId = FMemId WHERE FNewMemId IS NULL UPDATE A SET A.FNewMemId = B.FNewMemId FROM TImpMember AS B,TImpMemberCard AS A WHERE A.FMemId = B.FMemId AND B.FMemId != B.FNewMemId UPDATE A SET A.FNewMemId = B.FNewMemId FROM TImpMember AS B,TImpMemberCoursePack AS A WHERE A.FMemId = B.FMemId AND B.FMemId != B.FNewMemId SELECT * FROM SELECT * FROM TImpMember WHERE FNewMemId != FMemId AND FMemo != '' DELETE TMember WHERE FMemId IN(SELECT FNewMemId FROM TImpMember) 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 FNewMemId 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, 'G' AS FBirthdayType, FBirthday AS FBirthday, '' AS FTelephone, ISNULL(FMobile,'') AS FMobilePhone, '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, '' AS FAddress, 0 AS FProId, '' AS FCPW, '' AS FQPW, 0 AS FChargeEmpId, ISNULL( FNewPoint,0) AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, ISNULL(FMemo,'') AS FMemo, '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from TImpMember WHERE FNewMemId IN(SELECT FNewMemId FROM TImpMemberCard) AND FMemId = FNewMemId SELECT * FROM TImpMember WHERE FNewMemId = 76564036 SELECT * FROM TImpMemberCard WHERE FNewMemId = 76564036 AND FMemId = 76564036 SELECT * FROM TImpMember WHERE FMobile = '13969098625' AND FMemo NOT LIKE '%注销%' DELETE TMember WHERE FMemId IN(SELECT FNewMemId FROM TImpMember) SELECT * FROM TMember INSERT TMemberPointHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FMemo,FRecordTime) SELECT dbo.FNNewId(),A.FMemId,getdate(),0,1,'DR','Import',0,'',FNewPoint,0,FNewPoint,'',getdate() FROM TImpMember AS A WHERE FNewPoint != 0 AND A.FNewMemId = A.FMemId AND FMemo NOT LIKE '%注销%' DELETE TMemberPointHist WHERE FMemId IN(SELECT FNewMemId FROM TImpMember) SELECT * FROM TImpMember WHERE FMemId != FNewMemId /* SELECT * FROM TImpMember WHERE FMemId IN( SELECT FMemId,FMemNo,FName,FMobile,FGender,FCompId ,FBirthdayType ,FBirthday,FCreateDate,FPoint INTO #Temp FROM TImpMember GROUP BY FMemId,FMemNo,FName,FMobile,FGender,FCompId ,FBirthdayType ,FBirthday,FCreateDate,FPoint ORDER BY SUM(1) DESC ) SELECT FMemNO,SUM(1) FROM TIMpmember WHERE FMemId = FNewMemId GROUP BY FMemNO HAVING(SUM(1) > 1) SELECT FMemId FROM #Temp GROUP BY FMemId HAVING(SUM(1)) > 1 SELECT * FROM TImpmEMBER WHERE FMobile = '18765015301' UPDATE TImpMember SET FMemNo = '0000330' WHERE FMemId = 25463627 UPDATE TImpMember SET FMemNo = '0000055' WHERE FMemId = 25006217 */ SELECT count(1) FROM TImpMemberCard WHERE FMemo IS NULL INSERT INTO TMemberCard( FCardId, FCardNo, FCardFaceNo, FTypeId, FValueType, FCompId, FMemId, FState, FCreateDate, FExpiredDate, FTotalTimes, FUsedTimes, FSaleCompId, FSaleBillId, FMemo) SELECT FCardId AS FId, FCardNo AS FNo, FCardNo AS FFaceNo, FCardTypeId AS FTypeId, 1 AS FValueType, FCompId AS FCompId, FNewMemId AS FMemId, 1 AS FState, FCreateDate AS FCreateDate, FExpiredDate AS FExpiredDate, ISNULL(FRemainTimes,0) AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, FMemo AS FMemo FROM TImpMemberCard WHERE FNewMemId IN(SELECT FNewMemId FROM TImpMember) SELECT * FROM TImpMember WHERE FNewMemId = 76564036 SELECT * FROM TMember WHERE FMemId = 76564036 SELECT * FROM TImpMember WHERE FCardId IS NULL WHERE CardNo IS NOT NULL INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,0,FCreateDate,NULL AS FExpiredDate,'' FROM TImpMemberCard AS A WHERE FNewMemId IN(SELECT FMemId FROM TMember) 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 TImpMemberCard AS A WHERE FNewMemId IN(SELECT FMemId FROM TMember) INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,10,FBalance2,FBalance2,0,FCreateDate,NULL AS FExpiredDate,'' FROM TImpMemberCard AS A WHERE FBalance2 != 0 AND FNewMemId IN(SELECT FMemId FROM TMember) 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,10,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance2,0,A.FBalance2,0,getdate(),'从盛传中导入' FROM TImpMemberCard AS A WHERE FBalance2 != 0 AND FNewMemId IN(SELECT FMemId FROM TMember) --疗程 INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT FCardId,FMemId,FCardTypeId,0,FItemId,FCompId,FPurTimes,FPurTimes-FRemainTimes,FPurAmount,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'从盛传中导入',1,0 FROM TImpMemberCoursePack AS A INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,FCompId,FBillType,FBizType,FBillId,FBillNo,FBillDetailId,FRecordTime) SELECT dbo.FNNewId(),FMemId,A.FCardId AS FCardId,0, ISNULL(FCardTypeId,0),getdate(),FPurTimes,0,FPurTimes-FRemainTimes,0,FCompId,'DR','Import',0,'',0,getdate() FROM TImpMemberCoursePack AS A --年卡 INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT FCardId,FMemId,FCardTypeId,0,FItemId,FCompId,FPurTimes,FPurTimes-FRemainTimes,FPurAmount,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'从盛传中导入',FCalcMode,0 FROM TImpMemberYearCard AS A INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,FCompId,FBillType,FBizType,FBillId,FBillNo,FBillDetailId,FRecordTime) SELECT dbo.FNNewId(),FMemId,A.FCardId AS FCardId,0, ISNULL(FCardTypeId,0),getdate(),FPurTimes,0,FPurTimes-FRemainTimes,0,FCompId,'DR','Import',0,'',0,getdate() FROM TImpMemberYearCard AS A UPDATE A SET A.FCalcMode = 2 FROM TCourse AS A WHERE A.FId IN(SELECT FCourseId FROM TMemberCourse WHERE FCalcMode = 2) --欠款 ALTER TABLE TImpMemberArrear ADD FCompId BIGINT ALTER TABLE TImpMemberArrear ADD FMemId BIGINT ALTER TABLE TImpMemberArrear ADD FCardId BIGINT UPDATE A SET A.FMemId = MemId FROM TImpMemberArrear AS A UPDATE A SET A.FCardId = B.FCardId FROM TImpMemberArrear AS A,TImpMemberCard AS B WHERE A.MemID = B.MemId UPDATE TImpMemberArrear SET FCompId = dbo.FNCOmpId('006') INSERT TMemberArrear(FId,FMemId,FTime,FCompId,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid,FAcctArrear) SELECT dbo.FNNewId(),A.FMemId,getdate(),A.FCompId,'Account',A.FCardId,'DR_KK','DR_CardSale',0,单号,0,3,CAST(A.未还金额 AS FLOAT) ,0,0,0 FROM TImpMemberArrear AS A WHERE CAST(A.未还金额 AS FLOAT) > 0 --历史 SELECT * FROM TIMpMember WHERE MemId NOT IN(SELECT MemId FROM TImpMemberTransHist) SELECT * FROM TImpMemberTransHist SELECT * FROM TImpMemberTransHistDetail DELETE TImpMemberTransHist DELETE TImpMemberTransHistDetail ALTER TABLE TImpMemberTransHist ADD FCompId BIGINT UPDATE TImpMemberTransHist SET FCompID = DBO.FNCompId('001') UPDATE A SET A.FCompId = B.FCompId FROM TImpMemberTransHist as a,TIMpMember AS B WHERE A.MemId = B.memId INSERT TMemberOldTransHist(FId,FCompId,FMemId,FTime,FCardId,FBIllType,FBizType,FTransNo,FCOntent,FPrice,FQuantity,FAmount,FPayment,Femployee,FMemo) SELECT dbo.FNNewId(),C.FCompId,C.FNewMemId,REPLACE(消费时间,'消费日期:',''),CardId,'',LEFT(A.消费金额,4),A.单号, ISNULL(B.项目,''),0,1,A.实际入账,SUBSTRING(A.消费金额,5,len(消费金额)),B.员工, '' AS FMemo FROM TImpMemberTransHistDetail AS B,TImpMemberTransHist AS A,TImpMember AS C WHERE A.TransId = B.TransId AND A.MemId = C.MemId SELECT * FROM TImpMemberTransHistDetail update TMemberOldTransHist SET FEmployee = REPLACE(FEmployee,']','】') SELECT * FROM TMemberOldTransHist update TMemberOldTransHist SET FEmployee = REPLACE(FEmployee,'[','【') SELECT * FROM TMemberOldTransHist UPDATE TMemberOldTransHist SET FEmployee = '.' + FEmployee WHERE REPLACE(FEmployee,' ','') LIKE '[%' SELECT count(1) FROM TImpMember WHERE FAvatar IS NULL SELECT * FROM TImpMemberCard WHERE Cardid = 230729900 UPDATE TImpMember SET FAvatar = REPLACE(FAvatar,'\_2','') WHERE FAvatar LIKE '%\_2%' SELECT * FROM TImpMember WHERE FAvatar LIKE '%_2%' SELECT * FROM TMemberPhoto INSERT TMemberPhoto(FMemId,FType,FImage,FImagePath,FChangeId) SELECT FMemId,1,NULL,REPLACE(FAvatar,'http://files.sentree.com.cn/photo/850621/',''),1 FROM TImpMember WHERE ISNULL(FAvatar,'') != '' --员工 ALTER TABLE TImpEmployee ADD FPosId BIGINT SELECT * FROM TImpEmployee ALTER TABLE TImpEmployee ADD FPosName VARCHAR(100) ALTER TABLE TImpEmployee ADD FNo VARCHAR(20) ALTER TABLE TImpEmployee ADD FId BIGINT UPDATE TImpEmployee SET FId = dbo.FNNewId() UPDATE TImpEmployee SET FPosName = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(级别,'1',''),'2',''),'3',''),'添加此工位',''),'修改级别',''),'调店',''),'离职',''),' ',''),'复职','') INSERT TBasicType(FId,FNo,FKey,FName) SELECT dbo.FNNewId(),FPosName,'Position',FPosName FROM TImpEmployee GROUP BY FPosName INSERT TBasicTypeSub(FBasicTypeId,FCompId) SELECT A.FId,C.FId FROM TBasicType AS A,TCompany AS C WHERE A.FKey = 'Position' AND C.FId > 0 UPDATE A SET A.FPosId = B.FId FROM TImpEmployee AS A,TBasicType AS B WHERE A.FPosName = B.FName AND B.FKey = 'Position' UPDATE A SET A.FNo = B.FCompNo + A.编号 FROM TImpEmployee AS A,TImpCompany AS B WHERE A.shopId = B.shopId INSERT INTO TEmployee(FId,FNo,FName,FEnLname,FEnFname,FNickname,FDeptId,FPosId,FTechTypeId,FBriefCode,FGender,FStature,FWeight,FNationPlace,FNation,FEducation,FMarital,FAddress,FTelephone,FMobilePhone,FQQ,FEmail,FIdCard,FBirthdayType,FBirthday,FCardNo,FPW,FBank,FBankCardNo,FSSNo,FHCNo,FLinkMan,FLinkManTel,FLinkManAddr,FIsManager,FAllowBooking,FContractType,FState,FCreatorId,FCreateDate,FEntryDate,FExpiredDate,FLeaveDate,FPrice,FTags) SELECT FId,FNo,姓名,FEnLname = '',FEnFname = '',FNickname = 姓名,FDeptId = 0, FPosId,FTechTypeId = 0,FBriefCode = DBO.FNGetFirstPinYin(姓名),FGender = CASE WHEN 性别 = '男' THEN 1 ELSE 0 END, FStature = 0,FWeight = 0,FNationPlace = 0,FNation = 0,FEducation = '',FMarital = '',FAddress = '', FTelephone = '',FMobilePhone = 手机,FQQ = '',FEmail = '',FIdCard = 身份证号,FBirthdayType = CASE WHEN 生日 LIKE '农历' THEN 'L' ELSE 'G' END, FBirthday = RIGHT(生日,10), FCardNo = '',FPW ='',FBank = '',FBankCardNo = '',FSSNo = '',FHCNo ='',FLinkMan = '', FLinkManTel = '',FLinkManAddr = '' ,FAllowSign = 0,FAllowBooking = 1,FContractType = '', FState = 1,FCreatorId = 0,FCreateDate = GETDATE(),FEntryDate = 入职日期,FExpiredDate = null,FLeaveDate = null, FPrice = 0,FTags = '' FROM TImpEmployee WHERE 状态 = '在职' UPDATE TEmployee SET FBirthday = null where FBirthday = '1900-01-01' INSERT TEmployeeSub(FCompId,FEmpId,FSerialNo) SELECT C.FCompId,A.FId,A.编号 FROM TImpEmployee AS A,TImpCompany AS C WHERE A.ShopId = C.ShopId --产品 ALTER TABLE TImpGoods ADD FId BIGINT ALTER TABLE TImpGoods ADD FNo VARCHAR(50) ALTER TABLE TImpGoods ADD FUnitId BIGINT UPDATE TIMpGoods SET FNo = no INSERT TBasicType(FId,FNo,FKey,FName) SELECT dbo.FNNewId(),unit,'GoodsUnit',unit FROM TImpGoods WHERE unit NOT IN(SELECT FName FROM TBasicType WHERE FKey = 'GoodsUnit') AND Unit != '' GROUP BY unit UPDATE TImpGoods SET unit = '瓶' WHERE unit = '' INSERT TBasicTypeSub(FBasicTypeId,FCompId) SELECT A.FId,C.FId FROM TBasicType AS A,TCompany AS C WHERE A.FKey = 'GoodsUnit' AND C.FId > 0 AND A.FId NOT IN(SELECT FBasicTypeId FROM TBasicTypeSub) UPDATE A SET A.FUnitId = B.FId FROM TImpGoods AS A,TBasicType AS B WHERE A.unit = B.FName AND B.FKey = 'GoodsUnit' UPDATE A SET A.FNo = B.FCompNo + A.no FROM TIMpGoods AS A,TImpCompany AS B WHERE A.shopId = B.shopId UPDATE TImpGoods SET FNo = name WHERE FNo In( SELECT FNo FROM TImpGoods WHERE status = 1 GROUP BY FNo HAVING(SUM(1) > 1) ) INSERT INTO TGoods(FId,FNo,FName,FNoOfPad,FTypeId,FBriefCode,FUnitId,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FValuationMode,FBarCode,FEnabled,FSpecification,FPurUnitId,FConsUnitId,FSupplierId,FStoreId,FConsStoreId,FSaleStoreId,FMaxStock,FMinStock,FPeriodEnabled,FShelfLife,FDctId,FPointMode,FPointValue,FDeptId,FIsSale,FUnitLock,FDescription,FCustom1,FCustom2,FCustom3) SELECT id,FNo,name,FNo,FTypeId = 0,dbo.FNGetFirstPinYin(name), FUnitId,FSalePrice = cast(salePrice as float),FPurCostPrice = cast(inprice as float),FSaleCostPrice = 0,FConsCostPrice = 0, FValuationMode = 0,FBarCode = 0,FEnabled = 1,FSpecification = '', FPurUnitId = 0,FConsUnitId = 0,FSupplierId = 0,FStoreId = 0,FConsStoreId= 0,FSaleStoreId= 0, FMaxStock= 0,FMinStock= 0,FPeriodEnabled= 0,FShelfLife= 0,FDctId= 0,FPointMode= 0,FPointValue= 0, FDeptId= 0,FIsSale = 1,FUnitLock= 0,FDescription= '',FCustom1 = '',FCustom2 = '',FCustom3 = '' FROM TImpGoods WHERE status = 1 INSERT INTO TGoodsMultiUnit(FId,FGoodsId,FUnitType,FUnitId,FSequence,FConvDir,FConvRate,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock) SELECT dbo.FNNewId(),FId,1,FUnitId,1,1,1,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock FROM TGoods DELETE TGoodsMultiUnit INSERT TGoodsSub(FId,FGoodsId,FCompId) SELECT dbo.FNNewId(),A.ID,C.FCompId FROM TImpGoods AS A,TImpCompany AS C WHERE A.shopId = c.shopId AND status = 1 CREATE TABLE #Inventory ( FGoodsId BIGINT, FGoodsNo VARCHAR(100), FQuantity DECIMAL(18,6) ) INSERT #Inventory(FGoodsNo,FQuantity) UPDATE #Inventory SET FGoodsNO = replace(FGoodsNo,' ','') SELECT * FROM #Inventory UPDATE A SET A.FGoodsId = B.FId FROM #Inventory AS A,TGoods AS B WHERE A.FGoodsNo = B.FName SELECT * FROM #Inventory TInventory INSERT INTO TInventory(FId,FCompId,FGoodsId,FStoreId,FBatchNo,FProdDate,FPeriodDate,FQuantity) SELECT dbo.FNNewId(),1,FGoodsId,21001,'','','',FQuantity FROM #Inventory INSERT INTO TInventoryLog(FId,FCompId,FGoodsId,FStoreId,FBatchNo,FTime,FBillType,FBizType,FIOType,FBillId,FBillDetailId,FBillNo,FUnitId,FInQuantity,FOutQuantity,FInStdQuantity,FOutStdQuantity,FPrice,FAmount,FBalance,FOperatorId,FMemo) SELECT dbo.FNnewId(),1,A.FId,21001,'',getdate(),'DR','Import',22001,0,0,'',A.FUnitId,B.FQuantity,0,B.FQuantity,0,0,0,B.FQuantity,1,'导入' FROM TGoods AS A,#Inventory AS B WHERE A.FId = B.FGoodsId --项目 SELECT * FROM TImpItem --预约 SELECT barberName FROM TImpBooking GROUP BY barberName --员工 ALTER TABLE TImpBooking ADD FEmpId BIGINT UPDATE A SET A.FEmpId = B.FId FROM TImpBooking AS A,TEmployee AS B WHERE A.barberName = B.FName --项目 ALTER TABLE TImpBooking ADD FItems VARCHAR(1000) UPDATE A SET A.FItems = B.FId FROM TImpBooking AS A,TBasicType AS B WHERE B.FKey = 'BookingItem' AND REPLACE(categoryName,'类','') = B.FName OR(categoryName = '洗吹类' AND B.FName = '洗发') SELECT * FROM TImpBooking WHERE FItems IS NULL AND ISNULL(categoryName,'') != '' SELECT * FROM TBasicType WHERE FKey = 'BookingItem' SELECT * FROM TImpBooking --会员 ALTER TABLE TImpBooking ADD FCustName VARCHAR(1000),FCustMobile VARCHAR(1000),FCustGender INT UPDATE TImpBooking SET FCustName = custName,FCustMobile = memmobile,FCustGender = case when sex = 'M' then 1 else 0 end --门店 ALTER TABLE TImpBooking ADD FCompId BIGINT UPDATE TImpBooking SET FCompId = 1 -- ALTER TABLE TImpBooking ADD FSource VARCHAR(100) UPDATE TImpBooking SET FSource = 'WeChat' WHERE channel = 1 UPDATE TImpBooking SET FSource = 'Manual' WHERE channel != 1 ALTER TABLE TImpBooking ADD FStatus INT UPDATE TImpBooking SET FStatus = 2 INSERT INTO TBooking(FId,FCompId,FCreationTime,FBookingTime,FDuration,FEmpId,FCustName,FCustGender,FCustMobile,FItems,FMemo,FSource,FStatus,FReason,FRemindStep,FUnifiedRemind,FConfirmTime,FFinishTime,FCreatorId) SELECT id,FCompId,FCreateTime,FBookingTime,0,FEmpId,FCustName,FCustGender,FCustMobile,ISNULL(FItems,''),'',FSource,FStatus,'',0,0,FCreateTime,NULL,1 FROM TImpBooking