SELECT * FROM TBKMember# WHERE FMemNo = '259079' SELECT * FROM TMember WHERE FMemNo = '259079' SELECT * FROM TMember SELECT * FROM TMemberCard WHERE FMemId = 5584532119645354115 SELECT * FROM TMemberCourse WHERE FMemId = 5584532119645354115 SELECT * FROM TBKAccount# WHERE FMemId = 7247041615073293144 SELECT * FROM TImportConfig# SELECT * FROM TUser SELECT * FROM db108.s3_qd_8BAOBEIMENG6ky.dbo.gcm01 where FMemId = 7247041615073293144 SELECT * FROM TMemberOldTransHist WHERE FMemId = 7247041615073293144 DECLARE @NewMemId BIGINT DECLARE @OldMemId BIGINT SELECT @NewMemId = 5584532119645354115 SELECT @OldMemId = 7247041615073293144 UPDATE A SET A.FMemId = @NewMemId FROM TBKMember# AS A WHERE A.FMemId = @OldMemId UPDATE A SET A.FMemId = @NewMemId FROM TBKAccount# AS A WHERE A.FMemId = @OldMemId UPDATE A SET A.FMemId = @NewMemId FROM db108.s3_qd_8BAOBEIMENG6ky.dbo.gcm01 AS A WHERE A.FMemID = @OldMemId UPDATE A SET A.FMemId = @NewMemId FROM db108.s3_qd_8BAOBEIMENG6ky.dbo.gcm03 AS A WHERE A.FMemID = @OldMemId UPDATE A SET A.FMemId = @NewMemId FROM db108.s3_qd_8BAOBEIMENG6ky.dbo.gcm04 AS A WHERE A.FMemID = @OldMemId UPDATE A SET A.FMemId = @NewMemId FROM db108.s3_qd_8BAOBEIMENG6ky.dbo.gcm06 AS A WHERE A.FMemID = @OldMemId UPDATE A SET A.FMemId = @NewMemId FROM db108.s3_qd_8BAOBEIMENG6ky.dbo.gcm20 AS A WHERE A.FMemID = @OldMemId INSERT TMemberCard(FCardId,FCardNo,FCardFaceNo,FTypeId,FValueType,FCompId,FMemId,FState,FCreateDate,FExpiredDate,FTotalTimes,FUsedTimes,FSaleCompId,FSaleBillId,FMemo) SELECT FCardId,FCardNo,FCardNo AS FFaceNo,FTypeId,ISNULL(FValueType,0),FCompId,FMemId,FState,FCreateDate,FExpiredDate,FTotalTimes,FUsedTimes,FCompId AS FSaleCompId,0 AS FSaleBillId,FMemo FROM TBKMember# WHERE FMemId = 5584532119645354115 SELECT * FROM TMemberCardType WHERE FNo = '124' EXEC PExecImportSQL ' SELECT dbo.FNBKID(upper(gak01c)) AS FId , --类别代码 ISNULL(gak01c,'''') AS FNo, --类别名称 ISNULL(gak02c,'''') AS FName, --类别名称 ISNULL(gak03i,'''') AS FValueType , --大类(1-储值卡, 2- 资格卡,3-计次卡,4-单次卡) ISNULL(gak07f,'''') AS FValidityPeriod, --有效期限 ISNULL(gak08c,0) AS FValidityPeriodUnit , --期限单位 ISNULL(gak09f,'''') AS FPrice, --标准售价 ISNULL((SELECT TOP 1 FId FROM TPayAccount WHERE FBKAcctId = gak14i),0) AS FAcctId , --默认账户类别 ISNULL(gak16f,'''') AS FDeposit, --储值金额 ,Added by WUXM, 2004/02/16 ISNULL(gak06i,'''') AS FTimes, CASE gak29i WHEN 1 THEN 1 WHEN 0 THEN 2 WHEN 3 THEN 3 ELSE 0 END AS FMaterial, --卡介质类型 0磁卡 1IC卡,2 可视磁卡 3 可视IC卡 ISNULL((SELECT TOP 1 FId FROM TPayAccount WHERE FBKAcctId = gak35i),0) AS FAcctId2 , --第二账户类别 ISNULL(gak36f,'''') AS FDeposit2 , --第二账户金额 ISNULL((SELECT TOP 1 FId FROM TPayAccount WHERE FBKAcctId = gak37i),0) AS FAcctId3 , --第三账户类别 ISNULL(gak38f,'''') AS FDeposit3 , --第二账户金额 CASE WHEN gak41i = 1 THEN 0 ELSE 1 END AS FAllowSale, --停止销售 1停止 CASE WHEN gak42i = 1 THEN 0 ELSE 1 END AS FAllowRchg, --停止销售 1停止 ISNULL(gak43f,'''') AS FAlertBalance, --安全余额 Add by maql 2010/03/24 ISNULL(gak40f,'''') AS FMinRchgAmt, dbo.FNBKPointMode(gak30i) AS FSalePointMode, dbo.FNBKPointMode(gak30i) AS FRchgPointMode, ISNULL(CASE WHEN ISNULL(gak30i,0) NOT IN(0,1) THEN ISNULL(gak31i,0) / 100 ELSE gak31i END,0) AS FSalePointValue, ISNULL(CASE WHEN ISNULL(gak30i,0) NOT IN(0,1) THEN ISNULL(gak31i,0) / 100 ELSE gak31i END,0) AS FRchgPointValue, ISNULL(gak22f,0) AS FItemTurnoverRate , ISNULL(gak24f,0) AS FGoodsTurnoverRate, ISNULL(gak33f,0) AS FItemPointRate, ISNULL(gak34f,0) AS FGoodsPointRate INTO #CardType FROM {FDB}.gam10 WHERE gak00c = ''001'' AND gak01c = ''124'' INSERT {TDB}.TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FValidityPeriod,FValidityPeriodUnit,FAllowSale,FAllowRchg,FEnabled,FOrder,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue) SELECT FId,FNo,FName,FValueType,FMaterial,FPrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FValidityPeriod,FValidityPeriodUnit,FAllowSale,FAllowRchg,1,1,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue FROM #CardType ' -- SELECT * FROM TPayAccount ORDER BY FBKAcctId SELECT * FROM TMem --写入账户 EXEC PExecImportSQL ' INSERT INTO {TDB}.TMemberCardAccount(FId,FMemId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo) SELECT dbo.FNNewId(),FMemId,FCardId,FAcctId,FBalance,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo FROM TBKAccount# WHERE FBKAcctId NOT IN(3,4,888,999,889) --TODO AND FCardId IN(SELECT FCardId FROM TBKMember#) AND FMemId = 5584532119645354115' --delete Temp_Account_# WHERE FCardId = 7583214202515789572 --SELECT * FROM Temp_Account_# WHERE FAcctId IS NULL AND FCardId = 7714057480398863723 --写入积分 EXEC PExecImportSQL ' UPDATE A SET A.FPoint = B.FBalance FROM {TDB}.TMember AS A,TBKAccount# AS B WHERE A.FMemId = B.FMemId AND B.FBKAcctId = 3 ' --积分 --积分历史 EXEC PExecImportSQL ' DELETE {TDB}.TMemberPointHist WHERE FBillType = ''DR'' INSERT {TDB}.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,'''',FPoint,0,FPoint,'''',getdate() FROM {TDB}.TMember AS A WHERE FPoint != 0 ' --账户欠款 EXEC PExecImportSQL ' INSERT {TDB}.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,A.FAcctId,A.FArrear,0,0,A.FArrear FROM TBKAccount# AS A WHERE A.FArrear > 0 AND A.FAcctId IS NOT NULL AND FBKAcctId NOT IN(3,4,888,999,889) AND A.FMemId = 5584532119645354115 ' --账户历史 EXEC PExecImportSQL ' INSERT INTO {TDB}.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,A.FAcctId,getdate(),A.FCardTypeId,A.FCompId,''DR'',''Import'',0,'''',A.FBalance,0,A.FBalance,A.FArrear,getdate(),'''' FROM TBKAccount# AS A WHERE (A.FBalance > 0 OR A.FArrear > 0) AND FBKAcctId NOT IN(3,888,999,889) AND FMemId = 5584532119645354115 -- AND A.FAcctId NOT NULL' --疗程 EXEC PExecImportSQL ' SELECT FId AS FId, gca01c AS FMemNo, dbo.FNBkCompId(gcf00c) AS FCompId, M.FMemId AS FMemId, FItemId AS FItemId, FCourseId AS FCourseId, 0 AS FPackId, 0 AS FMemPackId, (SELECT TOP 1 FId FROM {TDB}.TBasicType WHERE FKey=''CourseType'') AS FTypeId, CASE WHEN ISNULL(gcf07f,0) > ISNULL(gcf05f,0) THEN ISNULL(gcf07f,0) ELSE ISNULL(gcf05f,0) END AS FPurTimes, CASE WHEN ISNULL(gcf07f,0) > ISNULL(gcf05f,0) THEN 0 ELSE ISNULL(gcf05f,0) - ISNULL(gcf07f,0) END AS FUsedPurTimes, -- CASE WHEN ISNULL(gcf10f,0) > ISNULL(gcf08f,0) THEN ISNULL(gcf10f,0) ELSE ISNULL(gcf08f,0) END AS FPurAmount, CAST (0 AS DECIMAL(18,6)) AS FPurAmount, gcf10f, ISNULL(dbo.FNBKDate(gcf11d),getdate()) AS FPurchaseDate, dbo.FNBKDate(gcf12d) AS FExpiredDate, ''DR.Import'' AS FBizType, 0 AS FTransId, 0 AS FArrear, 0 AS FDurable, '''' AS FMemo, CASE WHEN ISNULL(gcf22i,0) = 1 THEN 2 ELSE 1 END AS FCalcMode, 0 AS FFreeTimes, 0 AS FUsedFreeTimes, CAST(0 AS DECIMAL(18,6)) AS FAdjustPrice INTO TBKCourse# FROM {FDB}.gcm06,{FDB}.gcm01, {TDB}.TBKMember# AS M WHERE gcf00c = gca00c AND gca00c = gca13d AND gca01c = gcf01c AND gca01c = M.FCardNo AND gcf02c != '''' --疗程金额,根据剩余金额反算 UPDATE TBKCourse# SET FPurAmount = FPurTimes * (ISNULL(gcf10f,0) / (FPurTimes - FUsedPurTimes)) WHERE FPurTimes - FUsedPurTimes > 0 --核算单价 UPDATE TBKCourse# SET FAdjustPrice = FPurAmount / FPurTimes WHERE FPurTimes != 0 --select * from #Course WHERE FCourseId NOT IN (SELECT FId FROM {TDB}.TCourse) INSERT {TDB}.TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes, FPurAmount,FFreeTimes,FUsedFreeTimes,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice) SELECT FId,FMemId,ISNULL(FCourseId,0),FMemPackId,ISNULL(FItemId,0),FCompId,FPurTimes,FUsedPurTimes, FPurAmount,FFreeTimes,FUsedFreeTimes,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice FROM TBKCourse# ' EXEC PExecImportSQL ' INSERT INTO {TDB}.TMemberCourseHist(FId,FMemId,FMemCourseId,FPackId,FCourseId,FTime,FPurTimes,FFreeTimes,FUsePurTimes,FUseFreeTimes,FPurAmount,FFreeAmount,FUsePurAmount,FUseFreeAmount,FCompId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FRecordTime) SELECT dbo.FNNewId(),FMemId,A.FId AS FMemCourseId,0, ISNULL(FCourseId,0),getdate(),FPurTimes,FFreeTimes,0,0,FPurAmount,FFreeAmount,0,0,FCompId,''DR'',''Import'',0,'''',0,getdate() FROM {TDB}.TMemberCourse AS A ' --服务产品欠款 EXEC PExecImportSQL ' INSERT {TDB}.TMemberArrear(FId,FMemId,FTime,FCompId,FContentType,FCardId,FBillType,FBizType,FTransId,FTransNo,FTransDetailId,FContentId,FArrear,FEmpId,FRepaid) SELECT dbo.FNNewId(),A.FMemId,getdate(),A.FCompId,''DR_ItemGoods'',A.FCardId,''DR_XF'',''DR_Consume'',0,'''',0,0,A.FArrear,0,0 FROM TBKAccount# AS A WHERE A.FArrear > 0 AND A.FBKAcctId = 888' --疗程欠款 EXEC PExecImportSQL ' INSERT {TDB}.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,''DR_Course'',0,''DR_KK'',''DR_CardSale'',0,'''',0,A.FAcctId,A.FArrear,0,0,0 FROM TBKAccount# AS A WHERE A.FArrear > 0 AND A.FAcctId IS NOT NULL AND FBKAcctId IN(4) ' -- EXEC PExecImportSQL ' SELECT * FROM {FDB}.gcm04 WHERE NOT EXISTS(SELECT 1 FROM {TDB}.TPayAccount WHERE FBKAcctId = gcd02i) ' --老系统账户历史 EXEC PExecImportSQL ' SELECT dbo.FNNewId() AS FId, C.FCardId AS FCardId, C.FMemId AS FMemId, C.FTypeId AS FCardTypeId, dbo.FNBKCompId(gcd00c) AS FCompId, (SELECT FId FROM TPayAccount WHERE FBKAcctId = gcd02i) AS FAcctId, dbo.FNBKAcctOper(gcd05i) AS FBizType, '''' AS FBillType, 0 AS FTransId, gcd08c AS FTransNo, gcd05i , gcd06f,gcd10f, CASE WHEN gcd05i IN(0,6) THEN ISNULL(gcd06f,0) ELSE 0 END AS FInAmount, CASE WHEN gcd05i NOT IN(0,6) THEN ISNULL(gcd06f,0) ELSE 0 END AS FOutAmount, CASE WHEN gcd05i IN(0,6) THEN ISNULL(gcd06f,0) + ISNULL(gcd10f,0) ELSE ISNULL(gcd10f,0) - ISNULL(gcd06f,0) END AS FBalance, dbo.FNBKTime(gcd09d,gcd13t) AS FTime, ISNULL(dbo.FNBKTime(gcd11c,gcd13t),''1753-01-01'') AS FRecordTime, '''' AS FMemo, 0 AS FArrear INTO #AcctHist FROM {FDB}.gcm04 AS A, {TDB}.TBKMember# AS C WHERE A.gcd01c = C.FCardNo AND A.gcd02i NOT IN(4,888,999,889) AND C.FMemId = 5584532119645354115 INSERT INTO {TDB}.TMemberCardOldAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBizType,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo) SELECT FId,FMemId,FCardId,FAcctId,ISNULL(FTime,''1753-01-01''),FCardTypeId,FCompId,FBizType,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo FROM #AcctHist' --账户历史 /*SELECT * FROM s3_qd_NISIKA8HyvUt6pYGo..gcm04 SELECT C.FId AS FCardId, C.FMemId AS FMemId,*/ ----交易历史 --select * from TMemberOldTransHist --SELECT * FROM s3_qd_NISIKA8HyvUt6pYGo..gcm20 EXEC PExecImportSQL ' SELECT C.FCardId AS FCardId, C.FMemId AS FMemId, dbo.FNBKTime(gct04d,gct19t) AS FTime, dbo.FNBKCompId(gct00c) AS FCompId, CASE WHEN gct13c IN (''gn'',''gz'') THEN ''DR.KK'' WHEN gct13c =''gx'' THEN ''DR.XF'' ELSE ''DR'' END AS FBillType, dbo.FNBKTransBizType(gct06c) AS FBizType, gct14c AS FTransNo, isnull(gct07c,'''') + isnull(gct08c,'''') AS FContent, isnull(gct10f,0) AS FPrice, --标准单价 isnull(gct11f,0) AS FQuantity, --数量 isnull( gct12f,0) AS FAmount, --价格 CASE WHEN ISNULL(gct20c,'''') != '''' THEN (SELECT FName FROM {TDB}.TPayAccount WHERE FBKPayNo=gct20c) ELSE '''' END AS FPayment, CASE WHEN ISNULL(gct15c,'''') != '''' THEN ISNULL(gct15c,'''') + ''-'' + ISNULL((SELECT TOP 1 haa02c FROM {FDB}.ham01 WHERE haa00c = gct00c AND haa01c = gct15c),'''') + '','' ELSE '','' END +CASE WHEN ISNULL(gct16c,'''') != '''' THEN ISNULL(gct16c,'''') + ''-'' + ISNULL((SELECT TOP 1 haa02c FROM {FDB}.ham01 WHERE haa00c = gct00c AND haa01c = gct16c),'''') + '','' ELSE '','' END +CASE WHEN ISNULL(gct17c,'''') != '''' THEN ISNULL(gct17c,'''') + ''-'' + ISNULL((SELECT TOP 1 haa02c FROM {FDB}.ham01 WHERE haa00c = gct00c AND haa01c = gct17c),'''') + '','' ELSE '','' END +CASE WHEN ISNULL(gct18c,'''') != '''' THEN ISNULL(gct18c,'''') + ''-'' + ISNULL((SELECT TOP 1 haa02c FROM {FDB}.ham01 WHERE haa00c = gct00c AND haa01c = gct18c),'''') + '','' ELSE '','' END AS FEmployee INTO #TransHist FROM {FDB}.gcm20, {TDB}.TBKMember# AS C WHERE C.FCardNo = gct02c AND C.FMemId = 5584532119645354115 -- Truncate TABLE {TDB}.TMemberOldTransHist INSERT {TDB}.TMemberOldTransHist(FId,FCompId,FMemId,FTime,FCardId,FBIllType,FBizType,FTransNo,FCOntent,FPrice,FQuantity,FAmount,FPayment,Femployee,FMemo) SELECT dbo.FNNewId(),FCompId,FMemId,ISNULL(FTime,''1753-01-01''),FCardId,FBIllType,FBizType,FTransNo AS FTransNo,FCOntent,FPrice,FQuantity,FAmount,ISNULL(FPayment,''''),Femployee, '''' AS FMemo FROM #TransHist' --select * from TUser