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/非林/魅秀.sql

521 lines
16 KiB

USE TangShan_FeiLin
SELECT * FROM TImpMember3
SELECT * FROM TImpMember3 WHERE CUSTNO NOT IN (SELECT CUSTNO FROM TImpMember)
SELECT * INTO Guest FROM TangShan_FeiLin_MeiShow..Guest
SELECT * INTO Card FROM TangShan_FeiLin_MeiShow..Card
SELECT * INTO CardType FROM TangShan_FeiLin_MeiShow..CardType
SELECT * INTO Service FROM TangShan_FeiLin_MeiShow..Service
SELECT * INTO Employee FROM TangShan_FeiLin_MeiShow..Employee
SELECT * INTO job FROM TangShan_FeiLin_MeiShow..job
SELECT * INTO serviceType FROM TangShan_FeiLin_MeiShow..serviceType
SELECT * INTO ware FROM TangShan_FeiLin_MeiShow..ware
SELECT * INTO wareType FROM TangShan_FeiLin_MeiShow..wareType
SELECT * FROM Card
SELECT * FROM guest
--ťáÔą
ALTER TABLE Guest ADD FMemId BIGINT NOT NULL DEFAULT 0
ALTER TABLE Guest ADD FMemNo VARCHAR(50) NOT NULL DEFAULT ''
ALTER TABLE Guest ADD FName VARCHAR(50) NOT NULL DEFAULT ''
ALTER TABLE Guest ADD FGender INT NOT NULL DEFAULT 0
ALTER TABLE Guest ADD FMobile VARCHAR(50) NOT NULL DEFAULT ''
ALTER TABLE Guest ADD FMemo VARCHAR(1000) DEFAULT ''
ALTER TABLE Guest ADD FArrear DECIMAL(18,6) DEFAULT 0
ALTER TABLE Guest ADD FPoint DECIMAL(18,6) DEFAULT 0
ALTER TABLE Guest ADD FBirthday DATETIME
ALTER TABLE Guest ADD FBirthdayType CHAR NOT NULL DEFAULT ''
ALTER TABLE Guest ADD FCreateDate DATETIME
ALTER TABLE Guest ADD FExpiredDate DATETIME
ALTER TABLE Guest ADD FCompId BIGINT DEFAULT 0
ALTER TABLE Guest ADD FDeleted BIT NOT NULL DEFAULT 0
ALTER TABLE Guest ADD FPassword VARCHAR(1000) DEFAULT ''
SELECT * FROM Card
ALTER TABLE Card ADD FCardNo VARCHAR(50) NOT NULL DEFAULT ''
ALTER TABLE Card ADD FCardTypeId BIGINT NOT NULL DEFAULT 0
ALTER TABLE Card ADD FBalance DECIMAL(18,6) NOT NULL DEFAULT 0
ALTER TABLE Card ADD FRemainTimes INT NOT NULL DEFAULT 0
ALTER TABLE Card ADD FCompId BIGINT NOT NULL DEFAULT 0
ALTER TABLE Card ADD FCardId BIGINT NOT NULL DEFAULT 0
ALTER TABLE Card ADD FMemId BIGINT NOT NULL DEFAULT 0
ALTER TABLE Card ADD FCreateDate DATETIME
ALTER TABLE Card ADD FExpiredDate DATETIME
ALTER TABLE Card ADD FPoint DECIMAL(18,6) NOT NULL DEFAULT 0
ALTER TABLE Card ADD FPassword VARCHAR(50) NOT NULL DEFAULT ''
ALTER TABLE Card ADD FMemo VARCHAR(1000) NOT NULL DEFAULT ''
ALTER TABLE Card ADD FDeleted BIT NOT NULL DEFAULT 0
--ťáÔą×ĘÁĎ
SELECT * FROM Guest WHERE FMemNO = '00602'
SELECT * FROM Card WHERE FCardNo = '00602'
SELECT * FROM Guest WHERE FDeleted = 0
--ĂťÓĐż¨ľÄťáÔąŁŹąęźÇÎŞÉžłý
UPDATE Guest SET FDeleted = 1
WHERE Id NOT IN(SELECT GuestId FROM Card WHERE FDeleted = 0)
--ĂĹľę
UPDATE Guest SET FCompId = 1
--ťáÔąIDŁŹŁŤ100000
UPDATE Guest SET FMemId = 100000 + Id
--ĐŐĂű
UPDATE Guest SET FName = TrueName
--ľçť°
UPDATE Guest SET FMobile = PhoneNum
--ĐÔąđ
UPDATE Guest SET FGender = sex
--CreateDate
UPDATE Guest SET FCreateDate = AddDate
--ą¸×˘
UPDATE Guest SET FMemo = Remark
--ż¨
SELECT * FROM Card
--Éžłý
UPDATE Card SET FDeleted = Deleted
UPDATE Card SET FDeleted = 1
WHERE bChain = 1
--ĂĹľę
UPDATE Card SET FCompId = 1
--ż¨ID
UPDATE Card SET FCardId = 100000 + Id
--ťáÔąID
UPDATE Card SET FMemId = GuestId + 100000
--Ŕŕąđ
UPDATE Card SET FCardTypeId = 1000 + TypeId
--ż¨şĹ
UPDATE Card SET FCardNO = ContextId
--Óŕśî
UPDATE Card SET FBalance = Balance
--ťýˇÖ
UPDATE Card SET FPoint = CardPoint
--żŞż¨ČŐĆÚ
UPDATE Card SET FCreateDate = SellDate
--ÓĐЧĆÚ
UPDATE Card SET FExpiredDate = OutDate
--ĂÜÂë
UPDATE Card SET FPassword = ISNULL(Password,'')
--ą¸×˘
UPDATE Card SET FMemo = ISNULL(Remark,'')
--ťáÔąĂÜÂë
UPDATE A
SET A.FPassword = B.FPassword
FROM Guest AS A,Card AS B
WHERE A.FMemId = B.FMemId
AND A.FDeleted = 0
AND B.FDeleted= 0
--ťáÔąąŕşĹ
UPDATE A
SET A.FMemNo = B.FCardNO
FROM guest AS A,Card AS B
WHERE A.FMemId = B.FMemId
AND A.FDeleted = 0
AND B.FDeleted = 0
SELECT * FROM TMemberCardType
SELECT * FROM Guest WHERE Id = GuestId
SELECT FMemId,SUM(1)
FROM Card
WHERE FDeleted = 0
GROUP BY FMemId
HAVING(SUM(1) > 1)
SELECT * FROM Card WHERE FCardNo = '01302'
SELECT * FROM Guest WHERE FMemId = 100428
SELECT * FROM Card WHERE FMemId = 100428
SELECT * FROM TConsumeBill
SELECT FMemNO,sum(1)
FROM guest
WHERE FDeleted = 0
GROUP BY FMemNo
HAVING(SUM(1) > 1)
SELECT A.FName,A.FMobile,* FROM Card AS B,Guest AS A
WHERE B.FCardNo in(
SELECT FCardNo
FROM Card
WHERE FDeleted = 0
--AND bChain = 0
GROUP BY FCardNo
HAVING(SUM(1) > 1)
)
AND B.FDeleted = 0
AND A.FDeleted= 0
AND A.FMemId = B.FMemId
ORDER BY FCardNo
SELECT * FROM Card WHERE GuestId = 0
SELECT * FROM Card WHERE GuestId = 100330
SELECT * FROM guest WHERE FMemNo = '00758'
SELECT * FROM Card WHERE FCardNo = '02218'
SELECT * FROM Card WHERE bChain = 1
SELECT * FROM CardType WHERE id IN( 47,36)
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 FMemId AS FMemId,
FMemNo AS FMemNo,
FName AS FName,
dbo.FNGetFirstPinYin(FName),
0 AS FTypeId,
FCompId AS FCompId,
ISNULL(FCreateDate ,'1900-01-01') AS FCreateDate,
FGender AS FGender,
'G' AS FBirthdayType,
FBirthday AS FBirthday,
'' AS FTelephone,
ISNULL(FMobile,'') AS FMobilePhone,
'' AS FQQ,
'' AS FWeChat,
'' AS FIdCard,
'' AS FEmail,
'' AS FAddress,
0 AS FProId,
ISNULL(FPassword,'') AS FCPW,
'' AS FQPW,
0 AS FChargeEmpId,
ISNULL( FPoint,0) AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
ISNULL(FMemo,'') AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from Guest
WHERE FDeleted = 0
INSERT INTO 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 AS FTypeId,
(SELECT FValueType FROM TMemberCardType WHERE FId = FCardTypeId) AS FValueType,
FCompId AS FCompId,
FMemId AS FMemId,
1 AS FState,
FExpiredDate AS FCreateDate,
FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
FMemo AS FMemo
FROM Card
WHERE FDeleted = 0
AND FMemId IN(SELECT FMemId FROM TMember)
GROUP BY FCardNo,FCardTypeId,FCompId ,FMemId,FExpiredDate,FCreateDate,FCardId
UPDATE A
SET A.FMemo = B.FMemo,
A.FExpiredDate = B.FExpiredDate
FROM TMemberCard AS A,Card AS B
WHERE A.FCardId = B.FCardId
update TMemberCardAccount SET FExpiredDate = null
WHERE FCardTypeId IS NOT NULL
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,0,FCreateDate,DATEADD(year,1, FCreateDate) AS FExpiredDate,''
FROM Card AS A
WHERE FDeleted = 0
AND FMemId IN(SELECT FMemId FROM TMember)
INSERT TMemberCardAcctHist(FId,FMemId,FCardId,FAcctId,FTime,FCardTypeId,FCompId,FBillType,FBizType,FTransId,FTransNo,FInAmount,FOutAmount,FBalance,FArrear,FRecordTime,FMemo)
select dbo.FNNewId(),A.FMemId,A.FCardId,3,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'´ÓExcelÖĐľźČë'
FROM Card AS A
WHERE FDeleted = 0
AND FMemId IN(SELECT FMemId FROM TMember)
UPDATE TMemberCardAcctHist SET FMemo = ''
SELECT * FROM TImpTransLog WHERE żÍť§ąŕşĹ = 'A020935'
update A
SET A.FMemId
SELECT * FROM TMemberCard WHERE FId = 5494058162892437466
UPDATE A
SET A.FExpiredDate = B.FExpiredDate
FROM TMemberCard AS A,TImpMember3 AS B
WHERE A.FCardId = B.FCardId
SELECT * FROM TImpMember3
UPDATE A
SET A.FMemo = B.Rem
FROM TMemberCard AS A,TImpMember3 AS B
WHERE A.FCardId = B.FCardId
AND B.Rem IS NOT NULL
SELECT * FROM TMemberCardType
UPDATE TMemberCardType SET FId = FNo + 1000 WHERE FId > 0
UPDATE TMemberCard SET FTypeId = 0
DELETE TMemberCardTypeSUB
UPDATE A
SET A.FTypeId = B.CType + 1000
FROM TMemberCard AS A,TImpMember3 AS B
WHERE A.FCardId = B.FCardId
UPDATE TImpMember3 SET FCardTypeId = CType + 1000
SELECT * FROM TMemberCard WHERE FMemo != ''
delete TImpMember3 where CUSTNO IN(SELECT CUSTNO FROM TImpMember2)
SELECT * FROM fs.SaiDao_AppServer.dbo.TClient
SELECT * FROM card
WHERE GuestId = 273
SELECT GuestId ,SUM(1)
FROM card GROUP BY GuestId HAVING(SUM(1) > 1)
SELECT * FROM CardType WHERE Deleted = 0
AND Id NOT IN(SELECT TypeId FROM card WHERE Deleted = 0)
SELECT * FROM fs.QingDao_DieQiao.dbo.TMemberCardType
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 NOT EXISTS(SELECT TOP 1 1 FROM TItemSub AS B WHERE B.FCompId = C.FId AND B.FItemId = I.FId)
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 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 NOT EXISTS(SELECT TOP 1 1 FROM TBasicTypeSub AS B WHERE B.FCompId = C.FId AND B.FBasicTypeId = A.FId)
---ż¨Ŕŕąđ
INSERT TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRchgAmt,FValidityPeriod,FValidityPeriodUnit,FAllowSale,FAllowRchg,FEnabled,FOrder,FSalePointMode,FSalePointValue,FRchgPointMode,FRchgPointValue)
SELECT FId = Id + 1000,
FNo = id,
FName = Name,
1 AS FValueType,
2 AS FMaterial,
0 AS FPrice,
3 AS FAcctId,
0 AS FDeposit,
0 as FAcctId2,
0 AS FDeposit2,
0 AS FAcctId3,
0 AS FDeposit3,
0 AS FTimes,
0 AS FAlertBalance,
0 AS FMinRchgAmt,
0 AS FValidityPeriod,
0 AS FValidityPeriodUnit,
0 AS FAllowSale,
0 AS FAllowRchg,
1,
1,
0 AS FSalePointMode,
0 AS FSalePointValue,
0 AS FRchgPointMode,
0 AS FRchgPointValue
FROM cardType
--ĎîÄżŔŕąđ
SELECT * FROM ServiceType
UPDATE TMemberCardType SET FAllowSale = 1,FAllowRchg = 1,FExpiredDate = null
INSERT TBasicType(FId,FKey,FNo,FName)
SELECT 100000 + Id,'ItemType',Id,Name
FROM ServiceType
UPDATE TItem SET FNo = RIGHT('00' + FNo,3)
SELECT * FROM TMember WHERE FMemo != ''
--ĎîÄż
SELECT * FROM Service
INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FPointMode,FPointValue,FDeptId,FAllowBooking)
SELECT Id+1000,Id,Id,Name,Name,TypeId + 100000,dbo.FNGetFirstPinYin(Name),'',1,1,1,'','','',1,Price,Price,0,0,1,0,0,1
FROM Service
--Ôąš¤
--Ö°Îť
INSERT TBasicType(FId,FKey,FNo,FName)
SELECT 200000 + id,'Position',Id,Name FROM job
INSERT INTO TEmployee(FId,FNo,FName,FEnLname,FEnFname,FNickname,FDeptId,FPosId,FTechTypeId,FBriefCode,FGender,FStature,FWeight,FNationPlace,FNation,FEducation,FMarital,FAddress,FTelephone,FMobilePhone,FQQ,FEmail,FIdCard,FBirthdayType,FBirthday,
FCardNo,FPW,FBank,FBankCardNo,FSSNo,FHCNo,FLinkMan,FLinkManTel,FLinkManAddr,FIsManager,FAllowBooking,FContractType,FState,FCreatorId,FCreateDate,FEntryDate,FExpiredDate,FLeaveDate)
SELECT 1000+ id,ContextId,Name,'','',NickName,0,JobId + 200000,0,dbo.FNGetFirstPinYin(name),sex,0,0,'','','','',FamilyAddress,'',Phone,'','',Identiy,'G',Birth,
'','','','','','',FamilyName,FamilyTel,'',0,1,0,1,0,AddDate,AddDate,NULL,OutDate
FROM Employee
WHERE ContextId NOT LIKE '%ŔëÖ°%'
UPDATE TEmployee SET FDeptId = 5523957399072203416
SELECT * FROM Employee
SELECT ContextId ,SUM(1)
FROM Employee
GROUP BY ContextId
HAVING(SUM(1) > 1)
SELECT * FROM TBasicType WHERE FKey LIKE 'Dep%'
DELETE TEmployeeSub
INSERT TEmployeeSub(FEmpId,FSerialNo,FCompId)
SELECT E.FId,E.FNo,C.FId
FROM TEMployee AS E,TCompany AS C
WHERE C.FId != 0
AND E.FId != 0
--˛úơ
SELECT * FROM WareType
INSERT TBasicType(FId,FKey,FNo,FName)
SELECT 120000 + Id,'GoodsType',Id,Name
FROM WareType
SELECT * FROM TBasicType WHERE FKey = 'GoodsType'
SELECT Unit FROM ware
WHERE Unit NOT IN(SELECT FName FROM TBasicType)
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 dbo.FNNewId(),RIGHT('00' + CAST(Id AS VARCHAR),3),Name,'',120000 + TypeId,dbo.FNGetFirstPinYin(Name),
(SELECT FId FROM TBasicType WHERE FKey = 'GoodsUnit' AND FName = Unit),Price,FPurCostPrice = Cost,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,1,FUnitLock= 0,FDescription= '',FCustom1 = '',FCustom2 = '',FCustom3 = ''
FROM Ware
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
DELETE TGoodsMultiUnit
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 NOT EXISTS(SELECT TOP 1 1 FROM TGoodsSub AS B WHERE B.FCompId = C.FId AND B.FGoodsId = I.FId)
-- AND C.FId = 1
SELECT * FROM Guest WHERE FMemNO = '00646'
DELETE TMemberOldTransHist
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT A.ID,M.FMemId,A.AddDate,0,1,'DR',CASE WHEN TypeId = 2 THEN 'łäÖľ' ELSE 'ĎűˇŃ' END,ContectId,'',0,0,FactTotalMoney,'','',''
FROM TangShan_FeiLin_MeiShow..ConsumeContext AS A ,
TangShan_FeiLin_MeiShow..Consume AS B,
Guest AS M
WHERE A.CustomerId = M.Id
AND A.ConsumeId = B.Id
SELECT * FROM
TangShan_FeiLin_MeiShow..Consume
WHERE CustomerId = 2165
SELECT * FROM
TangShan_FeiLin_MeiShow..ConsumeContext
WHERE CustomerId = 2165