use wuhan_shaxuan SELECT * FROM TImpMember ORDER by id SELECT * FROM TImpMemberCard WHERE card_type_id = 3 SELECT old_card_num,sum(1) FROM TImpMemberCard GROUP BY old_card_num ORDER BY sum(1) desc SELECT card_id,card_name FROM TImpMemberCard GROUP BY card_id,card_name ORDER BY card_id,card_name SELECT card_type_id,sum(1) FROM TImpMemberCard GROUP BY card_type_id ORDER BY sum(1) desc DROP TABLE TImpMember DROP TABLE TImpMemberCard DROP TABLE TImpMemberTransHist SELECT * FROM TImpMemberTransHist DELETE TImpMemberTransHist ALTER TABLE TImpMember ADD FCardTypeName VARCHAR(100) ALTER TABLE TImpMember ADD FMemId BIGINT ALTER TABLE TImpMember ADD FMemNo VARCHAR(50) ALTER TABLE TImpMember ADD FCardNo VARCHAR(50) ALTER TABLE TImpMember ADD FName VARCHAR(50) ALTER TABLE TImpMember ADD FGender INT ALTER TABLE TImpMember ADD FCardState INT ALTER TABLE TImpMember ADD FMobile VARCHAR(50) ALTER TABLE TImpMember ADD FCardTypeId BIGINT ALTER TABLE TImpMember ADD FCourseId BIGINT ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6) ALTER TABLE TImpMember ADD FBalance2 DECIMAL(18,6) ALTER TABLE TImpMember ADD FRemainTimes INT ALTER TABLE TImpMember ADD FPurTimes INT ALTER TABLE TImpMember ADD FPurAmount DECIMAL(18,6) ALTER TABLE TImpMember ADD FItemId BIGINT ALTER TABLE TImpMember ADD FCreateDate DATETIME ALTER TABLE TImpMember ADD FExpiredDate DATETIME ALTER TABLE TImpMember ADD FCompId BIGINT ALTER TABLE TImpMember ADD FCardId BIGINT ALTER TABLE TImpMember ADD FMemo VARCHAR(1000) 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 FPW VARCHAR(200) 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 TImpMemberCard ADD FCardNo VARCHAR(1000) ALTER TABLE TImpMemberCard ADD FCompId BIGINT ALTER TABLE TImpMemberCard ADD FCardId BIGINT ALTER TABLE TImpMemberCard ADD FMemId BIGINT ALTER TABLE TImpMemberCard ADD FMemo VARCHAR(1000) ALTER TABLE TImpMemberCard ADD FArrear DECIMAL(18,6) ALTER TABLE TImpMemberCourse ADD FCreateDate DATETIME ALTER TABLE TImpMemberCourse ADD FExpiredDate DATETIME ALTER TABLE TImpMemberCourse ADD FCompId BIGINT ALTER TABLE TImpMemberCourse ADD FCardId BIGINT ALTER TABLE TImpMemberCourse ADD FMemId BIGINT ALTER TABLE TImpMemberCourse ADD FMemo VARCHAR(1000) ALTER TABLE TImpMemberCourse ADD FCardTypeId BIGINT ALTER TABLE TImpMemberCourse ADD FItemId BIGINT ALTER TABLE TImpMemberCourse ADD FRemainPurTimes INT ALTER TABLE TImpMemberCourse ADD FPurTimes INT ALTER TABLE TImpMemberCourse ADD FUsedPurTimes INT ALTER TABLE TImpMemberCourse ADD FPurAmount DECIMAL(18,6) ALTER TABLE TImpMemberCourse ADD FRemainFreeTimes INT ALTER TABLE TImpMemberCourse ADD FFreeTimes INT ALTER TABLE TImpMemberCourse ADD FUsedFreeTimes INT ALTER TABLE TImpMemberCourse ADD FFreeAmount DECIMAL(18,6) ALTER TABLE TImpMemberCourse ADD FAdjustPrice DECIMAL(18,6) --卡类别 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 =card_id, FNo = card_name,FName = card_name,card_type_id,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 TImpMemberCard WHERE card_type_id != 5 GROUP BY card_id,card_name,card_type_id INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled) SELECT dbo.FNNewId(),dbo.FNCompId('001'),I.FId,1,1,1 FROM TMemberCardType AS I WHERE I.FId NOT IN(SELECT FCardTypeId FROM TMemberCardTypeSub) DELETE TCourse WHERE FItemId IN(SELECT FID from tIMPItem) DELETE TItem WHERE FId IN(SELECT FID from tIMPItem) --项目 DROP TABLE TImpItem SELECT id AS id ,dbo.FNNewId() AS FId,name AS FName,dbo.FNNewId() AS FCourseId INTO TImpItem FROM TImpMemberCourse GROUP BY id,name INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FDisplayTypeId,FPointMode,FPointValue,FDeptId,FAllowBooking,FDisplay) SELECT FId,FName,FName,FName,FName,0,FBriefCode = dbo.FNGetFirstPinYin(FName), FDescription = '',FPriceMode = 0,FIsService = 1,FStatTimes = 1,FCustom1 = '',FCustom2 = '', FCustom3 = '',FEnabled = 1,0 ,FVipPrice = 0 ,FTime = 0,FDctId = 0 ,FDisplayTypeId = 0, FPointMode = 0,FPointValue = 0,FDeptId = 0,FAllowBooking = 1,FDisplay = 1 FROM TImpItem INSERT INTO TCourse(FId,FNo,FName,FBriefCode,FItemId,FPackId,FSequence,FTypeId,FTimes,FFreeTimes,FDurable,FValidityPeriodUnit,FValidityPeriod,FCreateDate,FExpiredDate,FDescription,FEnabled,FPrice,FAmount,FCalcMode) SELECT I.FCourseId, I.FName , I.FName , dbo.FNGetFirstPinyin(FName) AS FBriefCode, I.FId AS FItemId, 0 AS FPackId, 1 AS FSequence, 0 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 TImpItem AS I SELECT * FROM TImpMemberCourse WHERE mem_id = 2685182& SELECT * FROM TImpMember WHERE FCourseIsLoad = 0 SELECT * FROM TImpMember WHERE id = 2685182 UPDATE TImpMember SET FMemId = id UPDATE TImpMember SET FName = member_name UPDATE TImpMember SET FMobile = handset UPDATE TImpMember SET FGender = CASE WHEN gender = '男' THEN 1 ELSE 0 END UPDATE TImpMember SET FBirthday = Birth WHERE Birth != '' AND Birth != '0000-00-00' UPDATE TImpMember SET FBirthdayType = 'G' UPDATE TImpMember SET FBirthdayType = 'L' WHERE solar_birth = '0' UPDATE TImpMember SET FCompId = dbo.FNCompId('001') UPDATE TImpMember SET FPoint = point UPDATE TImpMember SET FPW = '' UPDATE TImpMember SET FPW = 'MD5-' + password WHERE password != '' UPDATE TImpMember SET FMemo = comment UPDATE A SET A.FCreateDate = B.create_date FROM TImpMember AS A,(SELECT member_id,MIN(create_date) AS create_date FROM TImpMemberCard GROUP BY member_id) AS B WHERE A.id = B.member_id UPDATE A SET A.FMemNo = B.old_card_num FROM TImpMemberCard AS B,TImpMember AS A,(SELECT member_id,MIN(create_date) AS create_date FROM TImpMemberCard GROUP BY member_id) AS C WHERE A.id = B.member_id AND B.member_id = C.member_id AND B.create_date = C.create_date UPDATE TImpMember SET FMemNO = FMobile WHERE FMemnO IS NULL SELECT * FROM TImpMemberCard SELECT * FROM TImpMemberCard UPDATE TImpMember SET FCourseIsLoad = 0 drop table TImpMemberCourse SELECT * FROM TImpMemberCourse --卡类别 UPDATE TImpMemberCard SET FCardTypeId = card_id --卡ID UPDATE TImpMemberCard SET FCardId = id --会员ID UPDATE TImpMemberCard SET FMemId = member_id UPDATE TImpMemberCard SET FCardNO = old_card_num UPDATE TImpMemberCard SET FCompId = dbo.FNCompId('001') UPDATE TImpMemberCard SET FCreateDate = create_date UPDATE TImpMemberCard SET FExpiredDate = expiry_date UPDATE TImpMemberCard SET FBalance = recharge_balance UPDATE TImpMemberCard SET FBalance2 = gift_balance UPDATE TImpMemberCard SET FArrear = 0 --次数 UPDATE TImpMemberCard SET FRemainTimes = recharge_count * 1+ gift_count * 1 --疗程 SELECT * FROM TImpMemberCourse SELECT * FROM TImpMemberCardDate UPDATE TImpMemberCourse SET FMemID = mem_id UPDATE TImpMemberCourse SET FCardId = dbo.FNNewId() WHERE FCardId IS NULL UPDATE A SET A.FItemId = B.FId, A.FCardTypeId = B.FCourseId FROM TImpMemberCourse AS A,TImpItem AS B WHERE A.id = B.id --单价 UPDATE TImpMemberCourse SET FAdjustPrice = per_performance UPDATE TImpMemberCourse SET FPurTimes = 0,FRemainPurTimes = 0,FUsedPurTimes = 0,FPurAmount = 0 UPDATE TImpMemberCourse SET FFreeTimes = 0,FRemainFreeTimes = 0,FUsedFreeTimes = 0,FFreeAmount = 0 UPDATE TImpMemberCourse SET FPurTimes = total_use_count WHERE is_gift = '0' UPDATE TImpMemberCourse SET FRemainPurTimes = use_count_balance WHERE is_gift = '0' UPDATE TImpMemberCourse SET FUsedPurTimes = FPurTimes - FRemainPurTimes WHERE is_gift = '0' UPDATE TImpMemberCourse SET FPurAmount = 0 WHERE is_gift = '0' UPDATE TImpMemberCourse SET FFreeTimes = total_use_count WHERE is_gift = '1' UPDATE TImpMemberCourse SET FRemainFreeTimes = use_count_balance WHERE is_gift = '1' UPDATE TImpMemberCourse SET FUsedFreeTimes = FPurTimes - FRemainPurTimes WHERE is_gift = '1' UPDATE TImpMemberCourse SET FFreeAmount = 0 WHERE is_gift = '1' UPDATE TImpMemberCourse SET FExpiredDate = expiry_date UPDATE TImpMemberCourse SET FCompId = dbo.FNCompId('001') UPDATE A SET A.FCreateDate = b.create_date FROM TImpMemberCardDate AS B,TImpMemberCourse AS A WHERE A.old_card_num = b.old_card_num AND A.mem_id = b.mem_id 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, '' AS FAddress, 0 AS FProId, FPW AS FCPW, '' AS FQPW, 0 AS FChargeEmpId, ISNULL( FPoint,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 FMemId IN(SELECT FMemId FROM TImpMemberCard) 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, (SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType, FCompId AS FCompId, FMemId AS FMemId, 1 AS FState, FCreateDate AS FCreateDate, ISNULL(FExpiredDate,DATEADD(YEAR,100,FCreateDate)) AS FExpiredDate, ISNULL(FRemainTimes,0) AS FTotalTimes, 0 AS FUsedTimes, FCompId AS FSaleCompId, 0 AS FSaleBillId, ISNULL(FMemo,'') AS FMemo FROM TImpMemberCard INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,ISNULL(A.FArrear,0),FCreateDate,NULL AS FExpiredDate,'' 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,'',A.FBalance,0,A.FBalance,A.FArrear,getdate(),'从美美发导入' FROM TImpMemberCard AS A --赠送的 INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,10,FBalance2,FBalance2,ISNULL(A.FArrear,0),FCreateDate,NULL AS FExpiredDate,'' FROM TImpMemberCard AS A WHERE 1=1 AND FBalance2 != 0 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,A.FArrear,getdate(),'从美美发导入' FROM TImpMemberCard AS A WHERE 1=1 AND FBalance2 != 0 DELETE TMemberCourse WHERE FId > 0 DELETE TMemberCourseLog WHERE FId > 0 INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FUsedFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT FCardId,FMemId,FCardTypeId,0,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FUsedFreeTimes,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'从美美发导入',1,FAdjustPrice FROM TImpMemberCourse 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,FFreeTimes,FUsedPurTimes,FUsedFreeTimes,FCompId,'DR','Import',0,'',0,getdate() FROM TImpMemberCourse AS A --交易历史 SELECT * FROM TImpMemberTransHist ALTER TABLE TImpMemberTransHist ADD FMemId BIGINT ALTER TABLE TImpMemberTransHist ADD FCompId BIGINT ALTER TABLE TImpMemberTransHist ADD FPayments VARCHAR(1000) ALTER TABLE TImpMemberTransHist ADD FAmount FLOAT UPDATE TImpMemberTransHist SET FCompId = dbo.FNCompId('001') UPDATE TImpMemberTransHist SET FMemId = mem_id UPDATE TImpMemberTransHist SET FPayments = replace(pay_type,'','') UPDATE TImpMemberTransHist SET FPayments = replace(FPayments,'
','') UPDATE TImpMemberTransHist SET FPayments = replace(FPayments,'
','') UPDATE TImpMemberTransHist SET FAmount = 0 UPDATE TImpMemberTransHist SET FAmount = cast(order_amount as float) WHERE order_amount != '-' INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo) SELECT dbo.FNNewId(),A.FMemId,A.create_time,0,A.FCompId,'DR','Import',item_type,item_name,FAmount,1,FAmount,FPayments,stylist_names,'' FROM TImpMemberTransHist AS A SELECT COUNT(1) FROM TIMPMember WHERE id IN(SELECT mem_id FROM TImpMemberCardDate) SELECT COUNT(1) FROM TIMPMember WHERE id IN(SELECT member_id FROM TImpMemberCard) or id IN(SELECT mem_id FROM TImpMemberCourse) SELECT * FROM TImpMember WHERE FMemId = 6124342 SELECT mem_id FROM TImpMemberCardDate WHERE mem_id nOT IN(SELECT id FROM TIMpMember) GROUP BY mem_id SELECT * FROM TImpMemberCardDate WHERE mem_id NOT IN(SELECT member_id FROM TImpMemberCard ) AND mem_id NOT IN(SELECT mem_id FROM TImpMemberCourse ) SELECT * FROM TImpMember WHERE id = 4052598 SELECT * FROM TImpMember WHERE id = 5635652 SELECT * FROM TMember WHERE FCPW != '' AND FCPW NOT LIKE 'MD%' ELECT TOP 1 1 FROM TMemberSaleBill WITH(NOLOCK) WHERE FAuditorId = @IUserId ) OR EXISTS(SELECT TOP 1 1 FROM TConsumeBill WITH(NOLOCK) WHERE FAuditorId = @IUserId ) OR EXISTS(SELECT TOP 1 1 FROM TOtherIncomeBill WITH(NOLOCK) WHERE FAuditorId = @IUserId ) OR EXISTS(SELECT TOP 1 1 FROM TExpensesBill WITH(NOLOCK) WHERE FAuditorId = @IUserId