You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sql-tools/pushItem.sql

138 lines
4.1 KiB

1 year ago
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 = '' --ԭ<EFBFBD>ŵ<EFBFBD>
SELECT @ToCompNo = '' --Ŀ<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>
SELECT @Clear = 1 --<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> 1=<EFBFBD><EFBFBD> 0=<EFBFBD><EFBFBD>
SELECT @Item = 1 --<EFBFBD><EFBFBD>Ŀ 1=<EFBFBD><EFBFBD> 0=<EFBFBD><EFBFBD>
SELECT @Goods = 1 --<EFBFBD><EFBFBD>Ʒ
SELECT @CardType = 1 --<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SELECT @BasicType = 1 --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @FromCompId BIGINT
DECLARE @ToCompId BIGINT
SELECT @FromCompId = dbo.FNCompId(@FromCompNo)
SELECT @ToCompId = dbo.FNCompId(@ToCompNo)
IF ISNULL(@FromCompId,0) = 0
BEGIN
RAISERROR('ԭ<EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',16,1)
RETURN
END
IF ISNULL(@ToCompId,0) = 0
BEGIN
RAISERROR('Ŀ<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',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')