use KunMing_XinMeiShiKong SELECT count(1) FROM imp_member where custid not in( SELECT custid FROM imp_member_trans_hist ) SELECT * FROM imp_member_trans_hist SELECT * FROM imp_member_trans_hist_detail SELECT consumeid FROM imp_member_trans_hist group by consumeid HAVING SUM(1) > 1 truncate table imp_member_trans_hist http://c.mgcloud.cn/BSA/Cash/queryConsumeDetailListAccount.do?accountForm.consumeObj.id=2103051608581360880&queryType=queryForConsumeInfo SELECT * FROM imp_member_course_detail WHERE goodsname like '%˫ʮһ%' SELECT * FROM imp_member_course WHERE goodsname like '%˫ʮһ%' SELECT * FROM imp_member_course_detail WHERE mode = 'S2302' SELECT * FROM imp_member SELECT * FROM TCompany sp_rename 'imp_member','TImpMember_1' DELETE imp_member WHERE ÐÕÃû is null select * from imp_member SELECT * FROM imp_company delete imp_company WHERE storeid not in(select storeid from imp_company where storename like '%±±³½%' OR storename like '%»ªÁú%' OR storename like '%½ð½­%') DELETE imp_member WHERE storeid not in(select storeid from imp_company) ±±³½µê£ºymbc001 ÃÜÂ룺ymbc001 ½ð½­µê£ºymjj001 ÃÜÂ룺ymjj001 »ªÁúµê£ºymhl001 ÃÜÂ룺ymhl001 ALTER TABLE imp_company ADD comp_id BIGINT UPDATE A SET A.comp_id = B.FId FROM imp_company AS A,TCompany AS B WHERE 1=1 AND A.storename like '%»ªÁú%' AND B.FName LIKE '%»ªÁú%' ALTER TABLE imp_member ADD mem_id BIGINT ALTER TABLE imp_member ADD card_id BIGINT ALTER TABLE imp_member ADD card_type_name VARCHAR(100) ALTER TABLE imp_member ADD mem_no VARCHAR(50) ALTER TABLE imp_member ADD card_no VARCHAR(50) ALTER TABLE imp_member ADD birthday_type VARCHAR(50) ALTER TABLE imp_member ADD birthday DATETIME ALTER TABLE imp_member ADD comp_id BIGINT ALTER TABLE imp_member ADD card_type_id BIGINT ALTER TABLE imp_member ADD memo VARCHAR(MAX) ALTER TABLE imp_member ADD balance DECIMAL(18,6) ALTER TABLE imp_member ADD balance2 DECIMAL(18,6) ALTER TABLE imp_member ADD point DECIMAL(18,6) ALTER TABLE imp_member ADD create_date DATETIME ALTER TABLE imp_member ADD expired_date DATETIME SELECT * FROM imp_member 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(),'' + cardname,cardname 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 imp_member WHERE cardname != '' group BY cardname UPDATE imp_member SET card_id = dbo.FNNewId() WHERE card_id IS NULL UPDATE imp_member SET mem_id = dbo.FNNewId() WHERE mem_id IS NULL SELECT * FROM imp_member UPDATE imp_member SET name = name UPDATE imp_member SET mobile = mobile UPDATE imp_member SET mem_no = accountno UPDATE imp_member SET card_no = accountno UPDATE imp_member SET point = 0 UPDATE imp_member SET balance = amount SELECT * FROM imp_member WHERE mem_no = '18213465825' UPDATE imp_member SET create_date = createdate UPDATE imp_member SET expired_date = DATEADD(YEAR,100,createdate) UPDATE A SET A.comp_id = b.comp_id FROM imp_member AS a,imp_company AS b WHERE a.storeid = b.storeid UPDATE A SET A.card_type_id = B.FId FROM imp_member AS A,TMemberCardType AS B WHERE A.cardname = B.FName UPDATE imp_member SET Birthday_Type = 'G' UPDATE imp_member SET Birthday = birthdate SELECT count(1) FROM imp_member_course SELECT * FROM imp_member_course SELECT * FROM imp_member_trans_hist drop table imp_member_trans_hist SELECT COUNT(1) FROM imp_member where memo is null select count(1) from imp_member where accountid not in( SELECT accountid FROM imp_member_course GROUP BY accountid) 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 mem_id AS FMemId, mem_no AS FMemNo, name AS FName, dbo.FNGetFirstPinYin(name), 0 AS FTypeId, comp_id AS FCompId, Create_Date AS FCreateDate, Gender AS FGender, Birthday_Type AS FBirthdayType, Birthday AS FBirthday, '' AS FTelephone, ISNULL(mobile,'') AS FMobilePhone, '' AS FQQ, '' AS FWeChat, '' AS FIdCard, '' AS FEmail, '' AS FAddress, 0 AS FProId, '' AS FCPW, '' AS FQPW, 0 AS FChargeEmpId, 0 AS FPoint, 1 AS FRecvConsSMS, 1 AS FRecvBulkSMS, memo AS FMemo, '' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5 from imp_member UPDATE imp_member SET mem_no = 'A' + Mem_no WHERE mem_no IN(SELECT FMemNO FROM TMember UNION ALL SELECT FCardNo FROM TMemberCard) UPDATE imp_member SET card_No = 'A' + card_no WHERE card_no IN(SELECT FMemNO FROM TMember UNION ALL SELECT FCardNo FROM TMemberCard) DELETE TMember WHERE FMemId IN(SELECT mem_id FROM imp_member) INSERT INTO TMemberCard( FCardId, FCardNo, FTypeId, FValueType, FCompId, FMemId, FState, FCreateDate, FExpiredDate, FTotalTimes, FUsedTimes, FSaleCompId, FSaleBillId, FMemo) SELECT card_id AS FId, card_no AS FNo, card_type_id AS FTypeId, (SELECT FValueType FROM TMemberCardType WHERE FId = card_type_id) AS FValueType, comp_id AS FCompId, mem_id AS FMemId, 1 AS FState, create_date AS FCreateDate, expired_date AS FExpiredDate, 0 AS FTotalTimes, 0 AS FUsedTimes, comp_id AS FSaleCompId, 0 AS FSaleBillId, '' AS FMemo FROM imp_member WHERE card_type_id is not null INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT mem_id,dbo.FNNewId(),card_id AS FCardId,3,balance,balance,0,create_date,NULL AS FExpiredDate,'' FROM imp_member WHERE card_type_id is not null INSERT TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) select dbo.FNNewId(),A.mem_id,A.card_id,3,getdate(),A.card_type_id,A.comp_id,'DR','Import',0,'',A.balance,0,A.balance,0,getdate(),'´ÓÀÏϵͳÖе¼Èë' FROM imp_member AS A WHERE card_type_id is not null SELECT * INTO imp_member_course_money FROM imp_member_course WHERE goods_typename = '»áÔ±¿¨' DELETE imp_member_course_money WHERE goods_typename = '»áÔ±¿¨' select dbo.FNNewId() AS id,dbo.FNNewId() AS course_id, '' + goodsname AS no, goodsname AS name INTO imp_item from imp_member_course WHERE goods_typename != '»áÔ±¿¨' GROUP BY goodsname INSERT imp_item(id,course_id,no,name) select dbo.FNNewId() AS id,dbo.FNNewId() AS course_id, '' + service AS no, service AS name from imp_member_course_detail WHERE service NOT IN(SELECT name FROM imp_item) GROUP BY service 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 id,no,name,name,name,0,dbo.FNGetFirstPinYin(name),'''',1,1,1,'''','''','''',1,0,0,0,0,0,0,0,1 FROM imp_item WHERE id NOT IN(SELECT FId FROM TItem) INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode) SELECT course_id AS FId, I.no + '', I.name + '' + '' AS FName, '' AS FBriefCode, I.id AS FItemId, 0 AS FPackId, 1 AS FSequence, (SELECT TOP 1 FId FROM TBasicType WHERE FKey = 'CourseType') AS FTypeId, 1 AS FTimes, 0 AS FFreeTimes, 0 AS FDurable, 0 AS FValidityPeriodUnit, 0 AS FValidityPeriod, getdate() AS FCreateDate, NULL AS FExpiredDate, '' AS FDescription, 1 AS FEnabled, 0 AS FPrice, 0 AS FAmount, 1 AS FCalcMode FROM imp_item AS I WHERE id NOT IN(SELECT FItemId FROM TCourse) 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 = '009' AND NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId) AND C.FId IN(SELECT 1 UNION ALL SELECT comp_id FROM imp_company) --Ì×²Í select dbo.FNNewId() AS id,dbo.FNNewId() AS course_id, '' + goodsname AS no, goodsname AS name INTO imp_course_pack from imp_member_course WHERE goods_typename = 'ÁƳ̿¨' GROUP BY goodsname INSERT TCoursePack(FId,FNo,FName,FBriefCode,FItemTimes,FGoodsQuantity,FValidityPeriod,FValidityPeriodUniT, FCreateDate,FExpiredDate,FDescription,FPrice,FDeptid,FAcctId,FDeposit,FEnabled,FAcctId2,FDeposit2) SELECT id,no,name AS FName,dbo.FNGetFirstPinYin(name) AS FBriefCode, 0 AS FItemTimes, 0 AS FGoodsQuantity, 0 AS FValidityPeriod, 0 AS FValidityPeriodUnit, GETDATE() AS FCreateDate, NULL AS FExpiredDate, '''' AS FDescription, 0 AS FPrice, 0 AS FDeptId, 0 AS FAcctId , 0 as FDeposit, 1 AS FEnabled, 0 AS FAcctId2, 0 as FDeposit2 FROM imp_course_pack --ÌײÍÁÆ³Ì SELECT * FROM imp_item WHERE name IN(SELECT goodsname FROM imp_member_course WHERE goods_typename = 'ÁƳ̿¨') AND( name NOT IN(SELECT service FROM imp_member_course_detail) OR name NOT IN(SELEct Goodsname FROM imp_member_course WHERE goods_typename != 'ÁƳ̿¨') ) AND id NOT IN(SELECT FItemId FROM TMemberCourse) ALTER TABLE imp_member_course ADD mem_id BIGINT ALTER TABLE imp_member_course ADD id BIGINT ALTER TABLE imp_member_course ADD course_id BIGINT ALTER TABLE imp_member_course ADD remain_times DECIMAL(18,6) ALTER TABLE imp_member_course ADD user_pur_times DECIMAL(18,6) ALTER TABLE imp_member_course ADD pur_amount DECIMAL(18,6) ALTER TABLE imp_member_course ADD comp_id BIGINT ALTER TABLE imp_member_course ADD item_id BIGINT ALTER TABLE imp_member_course ADD expired_date DATETIME ALTER TABLE imp_member_course ADD pur_times DECIMAL(18,6) ALTER TABLE imp_member_course ADD used_pur_times DECIMAL(18,6) ALTER TABLE imp_member_course ADD adjust_price DECIMAL(18,6) ALTER TABLE imp_member_course ADD memo NVARCHAR(1000) ALTER TABLE imp_member_course ADD calc_mode INT UPDATE A SET A.item_id = B.id, A.course_id = B.course_id FROM imp_member_course AS A,imp_item AS B WHERE A.goodsname = B.name UPDATE A SET A.mem_id = B.mem_id FROM imp_member_course AS A,imp_Member AS B WHERE A.accountid = B.accountid UPDATE a SET A.comp_id = B.comp_id FROM imp_member_course AS A,imp_company AS B WHERE a.storeid = b.storeid UPDATE imp_member_course SET create_date = start_date WHERE create_date = '' UPDATE imp_member_course SET id = dbo.FNNewId() UPDATE imp_member_course SET calc_mode = 1 UPDATE imp_member_course SET calc_mode = 1 UPDATE imp_member_course SET calc_mode = 2 WHERE times = -99 UPDATE imp_member_course SET expired_date = dateadd(month,cast(valid as float),start_date) WHERE times = -99 and valid_type = 0 UPDATE imp_member_course SET expired_date = dateadd(day,cast(valid as float),start_date) WHERE times = -99 and valid_type = 1 --Äê UPDATE imp_member_course SET pur_amount = cast(buy_amount as float) UPDATE imp_member_course SET pur_times = 0 WHERE times = -99 UPDATE imp_member_course SET pur_times = CAST(times AS FLOAT) WHERE times != -99 UPDATE imp_member_course SET used_pur_times = CAST(usedtimes AS FLOAT) WHERE usedtimes != -99 UPDATE imp_member_course SET adjust_price = CAST(price AS FLOAT) UPDATE imp_member_course SET memo = remark INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FPurAmount,FFreeTimes,FUsedPurTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT id,mem_Id,course_id,0,item_id,comp_Id,pur_times,ISNULL(pur_amount,0),0,used_pur_times,0,create_date,expired_date,'DR.Import',0,0,0,remark,calc_mode,ISNULL(adjust_price,0) FROM imp_member_course WHERE course_id is NOT null INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes, FCompId, FBillType,FBizType,FBillId,FBillNo,FBillDetailId) SELECT dbo.FNNewId(),mem_id,id,0,course_id,FTime = getdate(),pur_times,0,used_pur_times,0, comp_id, 'DR','Import',0,'',0 FROM imp_member_course WHERE course_id is NOT null --Ì×²Í --Ì×²Í ALTER TABLE imp_member_course ADD pack_id BIGINT ALTER TABLE imp_member_course_detail ADD mem_pack_id BIGINT ALTER TABLE imp_member_course_detail ADD item_id BIGINT ALTER TABLE imp_member_course_detail ADD mem_id BIGINT ALTER TABLE imp_member_course_detail ADD id BIGINT ALTER TABLE imp_member_course_detail ADD course_id BIGINT ALTER TABLE imp_member_course_detail ADD remain_times DECIMAL(18,6) ALTER TABLE imp_member_course_detail ADD user_pur_times DECIMAL(18,6) ALTER TABLE imp_member_course_detail ADD pur_amount DECIMAL(18,6) ALTER TABLE imp_member_course_detail ADD comp_id BIGINT ALTER TABLE imp_member_course_detail ADD item_id BIGINT ALTER TABLE imp_member_course_detail ADD expired_date DATETIME ALTER TABLE imp_member_course_detail ADD create_date DATETIME ALTER TABLE imp_member_course_detail ADD free_times DECIMAL(18,6) ALTER TABLE imp_member_course_detail ADD used_free_times DECIMAL(18,6) ALTER TABLE imp_member_course_detail ADD pur_times DECIMAL(18,6) ALTER TABLE imp_member_course_detail ADD used_pur_times DECIMAL(18,6) ALTER TABLE imp_member_course_detail ADD adjust_price DECIMAL(18,6) ALTER TABLE imp_member_course_detail ADD memo NVARCHAR(1000) ALTER TABLE imp_member_course_detail ADD calc_mode INT exec sp_rename 'imp_member_course_detail.id','orig_id' ALTER TABLE imp_member_course_detail ADD id BIGINT UPDATE A SET A.pack_id = b.id FROM imp_member_course AS A,imp_course_pack AS B WHERE a.goodsname = b.name UPDATE imp_member_course_detail SET id= dbo.FNNewId() UPDATE A SET A.mem_pack_id = B.id FROM imp_member_course_detail AS A,imp_member_course AS B WHERE a.detailid = B.detailid INSERT TMemberCoursePack(FId,FMemId,FPackId,FCompId,FItemTimes,FItemUsedTimes,FGoodsQuantity,FGoodsUsedQuantity,FAmount,FArrear,FPurchaseDate,FBizType,FTransId,FUseUp) SELECT A.id,A.mem_id,A.pack_id,A.comp_id,0,0,0,0,0,0,getdate(),'DR.Import',0,0 FROM imp_member_course AS A WHERE isnull(pack_id ,0) != 0 SELECT * FROM imp_member_course_detail UPDATE A SET A.mem_id = B.mem_id, A.comp_id = b.comp_id, a.create_date = b.create_date FROM imp_member_course_detail AS A,imp_member_course AS B WHERE a.detailid = b.detailid UPDATE imp_member_course_detail SET adjust_pric = price UPDATE imp_member_course_detail SET pur_times = times,used_pur_times = usedtimes UPDATE A SET A.item_id = b.id FROM imp_member_course_detail AS A,imp_item AS B WHERE a.service= b.name INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FPurAmount,FFreeTimes,FUsedPurTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT id,mem_Id,0,mem_pack_id,item_id,comp_Id,pur_times,ISNULL(pur_amount,0),isnull(free_times,0),used_pur_times,isnull(used_free_times,0),create_date,expired_date,'DR.Import',0,0,0,remark,calc_mode,ISNULL(adjust_price,0) FROM imp_member_course_detail UPDATE imp_member_course_detail SET free_times = times,used_free_times = usedtimes, pur_times = 0,used_pur_times = 0 WHERE modename = 'ÔùËÍ' SELECT * FROM imp_member_course_detail WHERE usedtimes > 0 UPDATE A SET A.calc_mode = b.calc_mode, A.expired_date = b.expired_date FROM imp_member_course_detail AS A,imp_member_course AS B WHERE A.detailid = b.detailid UPDATE imp_member_course_detail SET pur_times = 0 WHERE calc_mode = 2 INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FPackId,FItemId,FCourseId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes, FCompId, FBillType,FBizType,FBillId,FBillNo,FBillDetailId) SELECT dbo.FNNewId(),mem_id,id,mem_pack_id,item_id,0,FTime = getdate(),pur_times,isnull(free_times,0),used_pur_times,isnull(used_free_times,0), comp_id, 'DR','Import',0,'',0 FROM imp_member_course_detail SELECT * FROM imp_member_course WHERE detailid = '1226c77d-2cd2-4bbf-aa00-1fba8e366b83' SELECT * FROM imp_member_course_detail WHERE detailid = '1226c77d-2cd2-4bbf-aa00-1fba8e366b83' INSERT TMemberArrear(FId,FMemId,FTime,FCompId,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid,FAcctArrear) SELECT dbo.FNNewId(),A.mem_id,getdate(),A.comp_id,'Account',A.card_id,'DR_KK','DR_CardSale',0,'',0,3,A.arrears,0,0,0 FROM imp_member AS A WHERE cast(arrears as float) > 0 ALTER TABLE imp_member_trans_hist ADD comp_id BIGINT ALTER TABLE imp_member_trans_hist ADD mem_id BIGINT UPDATE a SET a.mem_id = b.mem_id FROM imp_member_trans_hist AS a,imp_member AS b WHERE a.custid = b.custid UPDATE a SET a.comp_id = b.comp_id FROM imp_member_trans_hist AS a,imp_company AS b WHERE a.storeid = b.storeid INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT DBO.FNNewId(),A.mem_id,a.create_date,0,A.comp_id,'DR','Import','',detailname,price,quantity,dis_price,'',isnull('','') ,'' FROM imp_member_trans_hist AS A ,imp_member_trans_hist_detail AS b WHERE a.consumeid = b.consumeid select * from imp_member_trans_hist SELECT * FROM imp_member_trans_hist_detail