DELETE TItemDiscountMaster SELECT * FROM TItemDiscountMaster EXEC PExecImportSQL ' INSERT {TDB}.TItemDiscountMaster(FId,FCompId,FItemId,FType,FCreateDate,FWeek,FTimeMode) SELECT FId,dbo.FNBKCompId(gdn00c) AS FCompId,FItemId,CASE WHEN gdn04i = 1 THEN 2 ELSE 1 END AS FTypeId,getdate() AS FCreateTime,gdn07c, gdn06i FROM {FDB}.gdm14 as a WHERE FItemId != '''' AND gdn03i = 1 AND gdn04i = 1 AND gdn00c != ''001'' -- AND a.gdf00c =''006'' ' UPDATE TItemDiscountMaster SET FTimeMode = 0 SELECT * FROM TItemDiscountMaster WHERE FId = 4692801313661198966 SELECT * FROM #Item EXEC PExecImportSQL ' UPDATE A SET A.FPayTypeId = B.FId FROM {FDB}.gdm15 AS A,TPayAccount AS B WHERE A.gdo03c = B.FBKAcctId -- AND a.gdg00c =''006'' ' EXEC PExecImportSQL ' INSERT {TDB}.TItemDiscountMid(FId, FParentId, FCardTypeId,FPayTypeId,FBeginDate,FEndDate) SELECT A.FId,A.FParentId,A.FCardTypeId,A.FPayTypeId,ISNULL(dbo.FNBKdate(A.gdo04d),''1753-01-01''),ISNULL(dbo.FNBKdate(A.gdo05d),''9999-12-31'') FROM {FDB}.gdm15 AS A WHERE FCardTypeID != '''' AND FParentId IN(SELECT FId FROM TItemDiscountMaster)' EXEC PExecImportSQL ' INSERT {TDB}.TItemDiscountDetail(FId,FParentId,FBeginTime,FEndTime,FCalcMode,FPriceMode,FValue,FMinValue) SELECT A.FId,A.FParentId,''1753-01-01'',''1753-01-01'',CASE WHEN gdp04i = 1 THEN 2 ELSE 1 END,2,ISNULL(gdp05f,0),0 FROM {FDB}.gdm16 AS A WHERE FParentId IN(SELECT FId FROM TItemDiscountMid) ' SELECT * FROM TItemDiscountDetail --删除没有这个项目的公司 EXEC PExecImportSQL ' delete TMemberCardTypeSub WHERE FId NOT IN( SELECT A.FId FROM TMemberCardTypeSub AS A, ( SELECT dbo.FNBkCompID(B.gak00c) AS FCompID, B.FId AS FItemId FROM {FDB}.gam10 AS B /* WHEREB.gak00c != ''001''*/) AS B WHERE A.FCompID = B.FCompId AND A.FCardTypeId = B.FItemId ) '