INSERT TMemberTransHistPayment(FMemId,FCardId,FBillType,FTransId,FTransDetailId,FPayTypeId,FPayAmt,FHistId) SELECT A.FMemId,A.FCardId,A.FBillType,A.FTransId,A.FTransDetailId,B.FPayTypeId,B.FPayAmt,0 FROM TMemberTransHist AS A,TConsumeGoodsPayment AS B WHERE B.FBillId = A.FTransId AND B.FDetailId = A.FTransDetailId AND A.FBizType = 'Goods' AND A.FTransId NOT IN(SELECT FTransId FROM TMemberTransHistPayment)