SELECT * FROM MMClient WHERE FMember != '' SELECT * FROM MMCard WHERE FCardState = '使用' SELECT CASE WHEN FClientName = '' THEN B.FCardNo ELSE FClientName END AS 姓名,CASE WHEN FMt !='' THEN Fmt ELSE FTel END AS 手机, CASE WHEN Fsex = '男' THEN FSex ELSE '女' END AS 性别,'公历' as 生日类型,'' as 生日, '001' AS 门店编号,B.FCardNo as 会员卡号,'A' + C.FCardTypeNo AS 储值卡类别,B.FBeginDate AS 开卡日期,DATEADD(YEAR,100,B.FBeginDate) AS 到期日期, b.fmoney AS 账户余额,0 as 账户欠款,'' as 账户备注 ,A.FMember AS 卡备注,'' as 账户备注,0 剩余次数,0 as 积分 FROM MMClient AS A,MMCard AS B,MMCardType AS C WHERE A.FClientSN = B.FClientSN AND B.FCardState = '使用' AND B.FCardTypeSN = C.FCardTypeSn SELECT * FROM MMCardType SELECT INSERT INTO qingdao_xiangzuo.dbo.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 = qingdao_xiangzuo.dbo.FNNewId(), 'A' + FCardTypeNo,FCardType,1,FMaterial = 2,FSNPrc,FCardFeeAmt = 0,FAcctId = 3,FDeposit = FInitMoney,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 MMCardType UPDATE MMCardType SET FCardTypeNo = 'A' + FCardTypeNo ALTER TABLE MMCardType ALTER COLUMN FCardTypeNo VARCHAR(10) SELECT FCardTypeNo FROM MMCardType GROUP BY FCardTypeNo HAVING SUM(1) > 1 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 > 1 AND C.FId != 0 AND C.FNo IN( '003','000','002') AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId)