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/Import/魅秀remote_2.sql

356 lines
11 KiB

1 year ago
SELECT * FROM TImpMember
WHERE FMemNo iS NULL
WHERE IsDel = 1
ORDER BY Id DESC
ALTER TABLE TImpMember ADD FCompId BIGINT
ALTER TABLE TImpMember ADD FMemId AS 100000 + ID
ALTER TABLE TImpMember ADD FName AS Name
ALTER TABLE TImpMember ADD FGender AS CASE Sex WHEN 0 THEN 1 ELSE 0 END
ALTER TABLE TImpMember ADD FBriefCode AS HelpMemory
ALTER TABLE TImpMember ADD FMobile AS PhoneNum
ALTER TABLE TImpMember ADD FCreateDate AS AddDate
ALTER TABLE TImpMember ADD FMemo AS Remark
ALTER TABLE TImpMember ADD FBirthday AS CASE WHEN ISNULL(Birth,'') = '' THEN '' ELSE CASE WHEN LEN(Birth) < 12 THEN '9999-' ELSE '' END + REPLACE(REPLACE(Birth,'BTrue',''),'BFalse','') END
ALTER TABLE TImpMember ADD FBirthdayType AS CASE WHEN Birth LIKE '%BFalse%' THEN 'L' ELSE 'G' END
ALTER TABLE TImpMember ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMemberCard ADD FCardNo VARCHAR(50)
ALTER TABLE TImpMemberCard ADD FMemId AS 100000 + GuestId
ALTER TABLE TImpMemberCard ADD FCardId AS 100000 + ID
ALTER TABLE TImpMemberCard ADD FCardTypeId AS CardTypeId
ALTER TABLE TImpMemberCard ADD FBalance AS MoneyAccountBalance
ALTER TABLE TImpMemberCard ADD FCreateDate AS AddDate
ALTER TABLE TImpMemberCard ADD FExpiredDate AS EndDate
ALTER TABLE TImpMemberCard ADD FValueType AS 1
ALTER TABLE TImpMemberCard ADD FCompId AS 1
ALTER TABLE TImpMemberCard ADD FCardState AS 1
ALTER TABLE TImpMemberCard ADD FRemainTimes AS 0
ALTER TABLE TImpMemberCard ADD FMemo AS ''
ALTER TABLE TImpMemberCard ADD FMemIndex INT
ALTER TABLE TImpMemberCard ADD FCardIndex INT
--<EFBFBD>ŵ<EFBFBD>
ALTER TABLE TImpCompany ADD FCompId BIGINT
UPDATE A
SET A.FCompId = B.FId
FROM TImpCompany AS A,TCompany AS B
WHERE B.FWebsite = A.ShopName
--
UPDATE A
SET A.FCompId = B.FCompId
FROM TImpMember AS A,TImpCompany AS B
WHERE A.ShopGUID = B.ShopGUID
UPDATE A
SET A.FCompId = B.FCompId
FROM TImpMemberCard AS A,TImpCompany AS B
WHERE A.ShopGUID = B.ShopGUID
UPDATE TImpMemberCard SET FMemIndex = 0;
UPDATE A
SET A.FMemIndex = (SELECT COUNT(1) FROM TImpMemberCard AS B WHERE B.GuestId = A.GuestId AND B.AddDate > A.AddDate)
FROM TImpMemberCard AS A
UPDATE A
SET A.FCardIndex = (SELECT COUNT(1) FROM TImpMemberCard AS B WHERE B.CardNum = A.CardNum AND B.AddDate > A.AddDate)
FROM TImpMemberCard AS A
UPDATE TImpMemberCard SET FCardNo = CardNum
UPDATE A
SET A.FCardNo = A.CardNum + '_' + CAST(A.FCardIndex AS VARCHAR)
FROM TImpMemberCard AS A
WHERE A.FCardIndex > 0
UPDATE A
SET A.FMemNo = A.FMobile
FROM TImpMember AS A
UPDATE A
SET A.FMemNo = A.FName
FROM TImpMember AS A
WHERE ISNULL(FMobile,'') = ''
UPDATE A
SET A.FMemNo = B.FCardNo
FROM TImpMember AS A,TImpMemberCard AS B
WHERE A.Id = B.GuestId
AND B.FIndex= 0
SELECT * FROM TImpMember
WHERE FMemNo iS NULL
SELECT FMemNo,SUM(1) FROM TImpMember
WHERE Id IN(SELECT GuestId FROM TImpMemberCard)
GROUP BY FMemNo
ORDER BY SUM(1) DESC
SELECT * FROM TImpMemberCard WHERE GuestId IN(
SELECT * FROM TImpMember WHERE FMemNo = '13206333611'
)
SELECT * FROM TImpMemberCard
GROUP BY CardTypeId,CardTypeName
SELECT * FROM TImpMemberCard WHERE GuestId = 1082
SELECT * FROM TImpMember WHERE Id = 9910
SELECT * FROM TMemberCardType
ORDER BY LEN(FName)
-- ALTER TABLE TMemberCardType ALTER COLUMN FName VARCHAR(100) NOT NULL DEFAULT ''
INSERT INTO TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FCardFeeAmt,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue,FPaySmsFee,FTimeCard,FValidityPeriod,FValidityPeriodUnit,FExpiredDate,FDefaultMemo,FCreateTime,FAllowSale,FAllowRchg,FDeptId,FEnabled,FOrder)
SELECT FId = ID,ID,REPLACE(dbo.FNToDBC(TypeName),' ',''),1,FMaterial = 2,0,FCardFeeAmt = 0,FAcctId = 3,FDeposit = 0,FAcctId2 = 0,FDeposit2 = 0 ,FAcctId3 = 0,FDeposit3 = 0,
FTimes = 0,FAlertBalance = 0,FMinRchgAmt = 0,FSalePointMode = 0,FSalePointValue = 0 ,FRchgPointMode = 0,FRchgPointValue = 0,FPaySmsFee = 0,FTimeCard = 0,FValidityPeriod = 100,FValidityPeriodUnit = 1,
FExpiredDate = NULL,FDefaultMemo = '',FCreateTime = GETDATE(),1,1,FDeptId = 0,FEnabled =1,FOrder = 1
FROM TImpCardType
INSERT INTO TMemberCardTypeSub(FId,FCompId,FCardTypeId,FAllowSale,FAllowRchg,FEnabled)
SELECT dbo.FNNewId(),C.FCompId,I.ID,1,1,1
FROM TImpCardType AS I,TImpCompany AS C
WHERE I.Id > 1
AND I.ShopGuid = C.ShopGuid
AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId)
UPDATE TImpMemberCard SET FCardNo
SELECT FCardNo
FROM TImpMemberCard
GROUP BY FCardNo
HAVING(SUM(1)) > 1
ORDER BY SUM(1) DESC
SELECT * FROM TImpMemberCard WHERE FCardNO = '1300056'
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա
INSERT INTO TMember(
FMemId,
FMemNo,
FName,
FBriefCode,
FTypeId,
FCompId,
FCreateDate,
FGender,
FBirthdayType,
FBirthday,FTelephone,FMobilePhone,FQQ,FWeChat,FIdCard,FEmail,FAddress,FProId,FCPW,FQPW,
FChargeEmpId,FPoint,FRecvConsSMS,FRecvBulkSMS,FMemo,FCustom1,FCustom2,FCustom3,FCustom4,FCustom5)
SELECT A.FMemId,
A.FMemNo,
A.FName,
A.FBriefCode,
0 AS FTypeId,
FCompId,
A.FCreateDate,
A.FGender,
A.FBirthdayType AS FBirthdayType,
A.FBirthday,
'' AS FTelephone,
A.FMobile,
'' AS FQQ,
'' AS FWeChat,
'' AS FIdCard,
'' AS FEmail,
'' AS FAddress,
0 AS FProId,
ISNULL('','') AS FCPW,
ISNULL('','') AS FQPW,
0 AS FChargeEmpId,
0 AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
A.FMemo AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TImpMember AS A
WHERE A.IsDel = 0
AND A.Id IN(SELECT GuestId FROM TImpMemberCard)
INSERT INTO dbo.TMemberCard(
FCardId,
FCardNo,
FCardFaceNo,
FTypeId,
FValueType,
FCompId,
FMemId,
FState,
FCreateDate,
FExpiredDate,
FTotalTimes,
FUsedTimes,
FSaleCompId,
FSaleBillId,
FMemo)
SELECT
FCardId AS FId,
FCardNo AS FNo,
FCardNo AS FFaceNo,
FCardTypeId,
FValueType,
FCompId AS FCompId,
FMemId AS FMemId,
FCardState AS FState,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
ISNULL(FRemainTimes,0) AS FTotalTimes,
0 AS FUsedTimes,
0 AS FSaleCompId,
0 AS FSaleBillId,
FMemo AS FMemo
FROM TImpMemberCard
WHERE IsDel = 0
UPDATE TMemberCard SET FExpiredDate = '9000-01-01' WHERE FExpiredDate = '1900-01-01'
INSERT TMemberCardAccount(FId,FMemId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT dbo.FNNewId(),FMemId,FCardId AS FCardId,3,ISNULL(FBalance,0),ISNULL(FBalance,0),0,FCreateDate,NULL,''
FROM TImpMemberCard
WHERE FCardId IS NOT NULL
WHERE FCalcMode != 1
INSERT dbo.TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo)
select dbo.FNNewId(),C.FMemId,A.FCardId,A.FAcctId,getdate(),C.FTypeId,C.FCompId,'DR','Import',0,'',ISNULL(A.FBalance,0),0,ISNULL(A.FBalance,0),0,getdate(),''
from dbo.TMemberCardAccount AS A,dbo.TMemberCard AS C,TImpMemberCard AS D
where C.FCardId = A.FCardId
AND C.FCardId = D.FCardId
--<EFBFBD><EFBFBD>Ʒ
SELECT * FROM TBasicType
INSERT TBasicType(FId,FKey,FNo,FName,FParentId,FDescription,FCustom,FOrder,FAllowEdit,FEnabled)
SELECT ProTypeID,'GoodsType',ProTypeID,MAX(ProTypeName),0,'','',0,-1,1
FROM TImpGoods
GROUP BY ProTypeID--,ProTypeName
INSERT TBasicTypeSub(FBasicTypeId,FCompId)
SELECT ProTypeID,FCompId
FROM TImpGoods,TImpCompany
GROUP BY ProTypeID,FCompId
SELECT * FROM TImpGoods WHERE ShopGuid = 'b82b6ecd-7fd6-4fa6-a0fc-18ce7969bfee'
SELECT * FROM TImpCompany
DELETE TGoodsSUb WHERE FGoodsId IN(SELECT ProId FROM TImpGoods)
ALTER TABLE TImpGoodsDetail ADD TypeId INT
UPDATE A
SET A.TypeId = B.ProTypeId
FROM TImpGoodsDetail AS A,TImpGoods AS B
WHERE A.Id = B.ProId
INSERT INTO TGoods(FId,FNo,FName,FNoOfPad,FTypeId,FBriefCode,FUnitId,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FValuationMode,FBarCode,FEnabled,FSpecification,FPurUnitId,FConsUnitId,FSupplierId,FStoreId,FConsStoreId,FSaleStoreId,FMaxStock,FMinStock,FPeriodEnabled,FShelfLife,FDctId,FPointMode,FPointValue,FDeptId,FIsSale,FUnitLock,FDescription,FCustom1,FCustom2,FCustom3)
SELECT ID,ID,TypeName,ID,FTypeId = TypeId,dbo.FNGetFirstPinYin(TypeName),
FUnitId = 20006,FSalePrice = TotalPrice,FPurCostPrice = 0,FSaleCostPrice = 0,FConsCostPrice = 0,
FValuationMode = 0,FBarCode = 0,FEnabled = 1,FSpecification = '',
FPurUnitId = 0,FConsUnitId = 0,FSupplierId = 0,FStoreId = 0,FConsStoreId= 0,FSaleStoreId= 0,
FMaxStock= 0,FMinStock= 0,FPeriodEnabled= 0,FShelfLife= 0,FDctId= 0,FPointMode= 0,FPointValue= 0,
FDeptId= 0,FIsSale = 1,FUnitLock= 0,FDescription= '',FCustom1 = '',FCustom2 = '',FCustom3 = ''
FROM TImpGoodsDetail
WHERE ShopGuid IN( 'b82b6ecd-7fd6-4fa6-a0fc-18ce7969bfee','d03ddab5-50ae-4503-9fa6-f388d3e1abd9')
AND isdel = 'False'
SELECT * FROM TImpGoodsDetail
select * from TImpGoodsDetail where id = 1377
SELECT * FROM TGoods WHERE FId > 90000
INSERT INTO TGoodsMultiUnit(FId,FGoodsId,FUnitType,FUnitId,FSequence,FConvDir,FConvRate,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock)
SELECT dbo.FNNewId(),FId,1,FUnitId,1,1,1,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock
FROM TGoods
WHERE FId IN(SELECT ID FROM TImpGoodsDetail)
INSERT TGoodsSub(FId,FGoodsId,FCompId)
SELECT dbo.FNNewId(),A.ID,C.FCompId
FROM TImpGoodsDetail AS A,TImpCompany AS C
WHERE A.ShopGUID = c.ShopGUID
AND A.ShopGUID = 'b82b6ecd-7fd6-4fa6-a0fc-18ce7969bfee'
AND A.isdel = 'false'
AND A.Id IN(SELECT FId FROM TGoods)
INSERT TGoodsSub(FId,FGoodsId,FCompId)
SELECT dbo.FNNewId(),A.ID,C.FCompId
FROM TImpGoodsDetail AS A,TImpCompany AS C
WHERE A.ShopGUID != 'b82b6ecd-7fd6-4fa6-a0fc-18ce7969bfee'
AND C.ShopGUID != 'b82b6ecd-7fd6-4fa6-a0fc-18ce7969bfee'
AND A.Id IN(SELECT FId FROM TGoods)
SELECT * FROM TCompany
INSERT TGoodsSub(FId,FGoodsId,FCompId)
SELECT dbo.FNNewId(),A.FGoodsId,C.FId
FROM TCompany AS C,TGoodsSub AS A
WHERE A.FCompId= 5061862835603384013
AND C.FId IN(4749754343985359438,5588794236132881698)
DELETE TGoodsSub WHERE FCompId IN(4749754343985359438,5588794236132881698)
DELETE TGoodsSub WHERE FGoodsId < 99999
SELECT * FROM TGoods WHERE FId = 4657648524007439829
SELECT * FROM TImpGoods
select * from TBasicType WHERE FKey = 'GoodsType'