select gca00c,gca01c,FCardTypeId INTO #Card FROM fromserver.ZYSDSH029.dbo.gcm01 WHERE gca00c = gca13d AND gca08i = 1 AND FCardTypeId != '0' GROUP BY gca00c,gca01c,FCardTypeId SELECT * FROM INSERT INTO TCardPresetSection(FId,FSectionNo,FCompId,FCardTypeId,FSalePrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FTotal,FUsed,FDisabled,FCreatorId,FCreateTime,FMemo) SELECT dbo.FNNewId(),dbo.FNNewId(),dbo.FNCompId('C'+gca00c),FCardTypeId,C.FPrice,3,C.FDeposit,0,0,0,0,0,1,getdate(),'µ¼Èë' FROM #Card AS A,TMemberCardType AS C WHERE C.FId = A.FCardTypeId AND dbo.FNCompId('C'+gca00c) is not null GROUP BY gca00c,FCardTypeId,FPrice,FDeposit SELECT * FROM #Card delete TCardPresetSection WHERE FCardTypeId IN(SELECT FCardTypeId FROM #Card) SELECT * FROM ZZYINS026..gam10 WHERE FId IN(6191112617464699755) INSERT TCardPresetDetail(FSectionId,FCardNo,FStatus) SELECT B.FId,A.gca01c,1 FROM #Card AS A,TCardPresetSection AS B WHERE dbo.FNCompId('C'+gca00c) = B.FCompId AND A.FCardTypeId = B.FCardTypeId