INSERT TItemSub(FId,FCompId,FItemId,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking,FEnabled) SELECT dbo.FNNewId(),C.FId,I.FId,I.FPrice,I.FVipPrice,I.FTime,I.FDctId,I.FPointMode,I.FPointValue,I.FDeptId,I.FAllowBooking,I.FEnabled FROM TItem AS I,TCompany AS C WHERE I.FId != 0 AND C.FId != 0 --AND C.FNo = '009' AND NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId) INSERT TGoodsSub(FId,FCompId,FGoodsId) SELECT dbo.FNNewId(),C.FId,I.FId FROM TGoods AS I,TCompany AS C WHERE I.FId != 0 AND C.FId != 0 -- AND C.FNo = '009' AND NOT EXISTS(SELECT TOP 1 1 FROM TGoodsSub AS B WHERE B.FCompId = C.FId AND B.FGoodsId = I.FId) -- AND C.FId = 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 = '009' AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId) INSERT TBasicTypeSub(FBasicTypeId,FCompId) SELECT A.FId,C.FId FROM TBasicType AS A,TCompany AS C WHERE A.FId > 0 AND C.FId > 0 --AND C.FNo = '009' AND NOT EXISTS(SELECT TOP 1 1 FROM TBasicTypeSub AS B WHERE B.FCompId = C.FId AND B.FBasicTypeId = A.FId) DECLARE @FromCompNo VARCHAR(20) DECLARE @ToCompNo VARCHAR(20) DECLARE @Item BIT DECLARE @Goods BIT DECLARE @CardType BIT DECLARE @BasicType BIT DECLARE @Clear BIT SELECT @FromCompNo = '' --原门店 SELECT @ToCompNo = '' --目的门店 SELECT @Clear = 1 --是否清空现有的 1=是 0=否 SELECT @Item = 1 --项目 1=是 0=否 SELECT @Goods = 1 --产品 SELECT @CardType = 1 --储值卡类别 SELECT @BasicType = 1 --基本类别资料 DECLARE @FromCompId BIGINT DECLARE @ToCompId BIGINT SELECT @FromCompId = dbo.FNCompId(@FromCompNo) SELECT @ToCompId = dbo.FNCompId(@ToCompNo) IF ISNULL(@FromCompId,0) = 0 BEGIN RAISERROR('原门店编号不存在',16,1) RETURN END IF ISNULL(@ToCompId,0) = 0 BEGIN RAISERROR('目标门店编号不存在',16,1) RETURN END IF @Item = 1 BEGIN IF @Clear = 1 BEGIN DELETE TItemSub WHERE FCompId = @ToCompId END INSERT TItemSub(FId,FCompId,FItemId,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking,FEnabled) SELECT dbo.FNNewId(),@ToCompId,FItemId,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking,FEnabled FROM TItemSub AS I WHERE FCompId = @FromCompId AND NOT EXISTS(SELECT 1 FROM TItemSub AS B WHERE B.FCompId=@ToCompId AND FItemId = I.FItemId) END IF @Goods = 1 BEGIN IF @Clear = 1 BEGIN DELETE TGoodsSub WHERE FCompId = @ToCompId END INSERT TGoodsSub(FId,FCompId,FGoodsId) SELECT dbo.FNNewId(),@ToCompId,FGoodsId FROM TGoodsSub I WHERE FCompId = @FromCompId AND NOT EXISTS(SELECT 1 FROM TGoodsSub AS B WHERE B.FCompId=@ToCompId AND B.FGoodsId = I.FGoodsId) -- AND C.FId = 1 END IF @CardType = 1 BEGIN IF @Clear = 1 BEGIN DELETE TMemberCardTypeSub WHERE FCompId = @ToCompId END INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled) SELECT dbo.FNNewId(),@ToCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled FROM TMemberCardTypeSub AS I WHERE FCompId = @FromCompId AND NOT EXISTS(SELECT 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId=@ToCompId AND B.FCardTypeId = I.FCardTypeId) END IF @BasicType = 1 BEGIN IF @Clear = 1 BEGIN DELETE TBasicTypeSub WHERE FCompId = @ToCompId END INSERT TBasicTypeSub(FBasicTypeId,FCompId) SELECT FBasicTypeId,@ToCompId FROM TBasicTypeSub AS I WHERE FCompId = @FromCompId AND NOT EXISTS(SELECT 1 FROM TBasicTypeSub AS B WHERE B.FCompId=@ToCompId AND B.FBasicTypeId = I.FBasicTypeId) END RETURN DELETE TSystemParamSub WHERE FCompId = dbo.FNCompId('011') INSERT TSystemParamSub(FParamKey,FCompId,FValue) SELECT FParamKey,dbo.FNCompId('011'),FValue FROM TSystemParamSub WHERE FCompId = dbo.FNCompId('009')