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/摩登/SQLQuery14.sql

382 lines
13 KiB

1 year ago
use qingdao_modenglishe
SELECT * FROM TMGJMember
SELECT *F
SELECT count(1) FROM TMGJMember
SELECT * FROM TMGJCard
SELECT * FROM TMGJMemberHist
SELECT * FROM TMGJMemberHistItem
SELECT * FROM TMGJEmployee
SELECT * FROM TMGJGoods
SELECT * FROM TMGJItem
SELECT * FROM TMGJItemType
SELECT * FROM TMGJGoodsType
SELECT * FROM TEmployee
SELECT * FROM TMGJEmployee
DELETE TEmployee WHERE FId > 0
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,FCardPW,FPW,FBank,FBankCardNo,FSSNo,FHCNo,FLinkMan,FLinkManTel,FLinkManAddr,FIntroducer,FAllowSign,FAllowBooking,FContractType,FState,FCreatorId,FCreateDate,FEntryDate,FExpiredDate,FLeaveDate,FDescription,FCustom1,FCustom2,FCustom3,FPrice,FTags)
SELECT employeeId,RIGHT('00' + employeeCode,3),employeeName,FEnLname = '',FEnFname = '',FNickname = employeeName,FDeptId = 0,
0,FTechTypeId = 0,FBriefCode = DBO.FNGetFirstPinYin(employeeName),FGender = 0,
FStature = 0,FWeight = 0,FNationPlace = 0,FNation = 0,FEducation = '',FMarital = '',FAddress = '',
FTelephone = '',FMobilePhone = '',FQQ = '',FEmail = '',FIdCard = '',FBirthdayType = 'L',FBirthday = NULL,
FCardNo = '',FCardPW = '',FPW ='',FBank = '',FBankCardNo = '',FSSNo = '',FHCNo ='',FLinkMan = '',
FLinkManTel = '',FLinkManAddr = '',FIntroducer = '' ,FAllowSign = 0,FAllowBooking = 1,FContractType = '',
FState = 1,FCreatorId = 0,FCreateDate = GETDATE(),FEntryDate = null,FExpiredDate = null,FLeaveDate = null,
FDescription = '',FCustom1 = '',FCustom2 = '',FCustom3 ='',FPrice = 0,FTags = ''
FROM TMGJEmployee
WHERE employeeName != '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʦ'
INSERT TEmployeeSub(FEmpId,FCompId,FSerIAlNo)
SELECT FId,1,FNo
FROM TEMployee
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 productId,productCode,productName,productCode,categoryId,dbo.FNGetFirstPinYin(productName),
(SELECT FId FROM TBasicType AS A WHERE A.FName = B.UNIT),cast(price as decimal(18,6)),FPurCostPrice = 0,FSaleCostPrice = 0,FConsCostPrice = 0,
FValuationMode = 0,FBarCode = barcode,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 TMGJGoods AS B
SELECT * FROM TGoods
UPDATE TMGJGoods SET productCode = productCode + '_' + cast(productId AS VARCHAR)
WHERE productCode IN(
SELECT productCode FROM TMGJGoods
group by productCode
having(count(1) > 1))
DELETE TItem WHERE FId > 0
DELETE TItemSub
INSERT TItem(FId,FNo,FNoOfPad,FName,FAbbr,FTypeId,FBriefCode,FDescription,FPriceMode,FIsService,FStatTimes,FCustom1,FCustom2,FCustom3,FEnabled,FPrice,FVipPrice,FTime,FDctId,FDisplayTypeId,FPointMode,FPointValue,FDeptId,FAllowBooking)
SELECT typeId,code,code,typeName,typeName,parentId,FBriefCode = dbo.FNGetFirstPinYin(typeName),
FDescription = '',FPriceMode = 0,FIsService = 1,FStatTimes = 1,FCustom1 = '',FCustom2 = '',
FCustom3 = '',FEnabled = 1,price ,FVipPrice = price ,FTime = 0,FDctId = 0 ,FDisplayTypeId = 0,
FPointMode = 0,FPointValue = 0,FDeptId = 0,FAllowBooking = 1
FROM TMGJItem
UPDATE TItem SET FNo = RIGHT('000' + FNo,3)
WHERE LEN(Fno ) < 3
UPDATE TMGJItem SET code = code + '_' + cast(typeId AS VARCHAR)
WHERE code IN(
SELECT code FROM TMGJItem
GROUP BY code
HAVING(SUM(1) > 1))
SELECT * FROM TMGJItem WHERE code = '710'
SELECT code FROM TMGJItem
GROUP BY code
HAVING(SUM(1) > 1)
SELECT * FROM TMGJItem
SELECT * FROM TMGJItemType
SELECT * FROM TBasicType WHERE FKey = 'ITEMtYPE'
DELETE TBasicType WHERE FKey = 'ITEMtYPE'
DELETE TBasicTypeSub WHERE FBasicTypeId IN(SELECT FId FROM TBasicType WHERE FKey = 'ITEMtYPE')
DELETE TBasicType WHERE FKey = 'GoodsType'
DELETE TBasicTypeSub WHERE FBasicTypeId IN(SELECT FId FROM TBasicType WHERE FKey = 'GoodsType')
INSERT TBasicType(FId,FNo,FKey,FName)
SELECT categoryId ,categoryId,'ItemType',categoryName
FROM TMGJItemType
INSERT TBasicType(FId,FNo,FKey,FName)
SELECT categoryId ,categoryId,'GoodsType',categoryName
FROM TMGJGoodsType
ALTER TABLE TMGJCard ADD memId VARCHAR(100)
SELECT * INTO TMember_SD FROM TMember
SELECT * INTO TMemberCard_SD FROM TMemberCard
SELECT * INTO TMemberCardAccount_SD FROM TMemberCardAccount
SELECT * INTO TMemberCardAcctHist_SD FROM TMemberCardAcctHist
SELECT * INTO TMemberTransHist_SD FROM TMemberTransHist
DROP TABLE TMemberCardAcctHist_SD
DELETE TMemberCardAcctHist
DELETE TMemberCardAccount
DELETE TMemberCard WHERE FCardid > 0
DELETE TMember WHERE FMemId > 0
DELETE TMember
SELECT ' DELETE ' + NAME FROM sysobjects WHERE name like 'TMemberSale%'
SELECT * FROM TMGJCardType
DROP TABLE TMGJCardType
SELECT * FROM TMGJMember
SELECT * FROM TMGJCard
select DATEADD(second,cast(createtime as bigint) / 1000,'1970-01-01 00:00:00')
FROM
TMGJCard
ORDER BY createtime desc
ALTER TABLE TMGJMember ADD FMemId BIGINT
ALTER TABLE TMGJMember ADD FCardNo VARCHAR(50)
ALTER TABLE TMGJMember ADD FMemNo VARCHAR(50)
ALTER TABLE TMGJMember ADD FName VARCHAR(50)
ALTER TABLE TMGJMember ADD FGender INT
ALTER TABLE TMGJMember ADD FMobile VARCHAR(50)
ALTER TABLE TMGJMember ADD FCardTypeId BIGINT
ALTER TABLE TMGJMember ADD FCourseId BIGINT
ALTER TABLE TMGJMember ADD FBalance DECIMAL(18,6)
ALTER TABLE TMGJMember ADD FBalance2 DECIMAL(18,6)
ALTER TABLE TMGJMember ADD FRemainTimes INT
ALTER TABLE TMGJMember ADD FPurTimes INT
ALTER TABLE TMGJMember ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TMGJMember ADD FItemId BIGINT
ALTER TABLE TMGJMember ADD FCreateDate DATETIME
ALTER TABLE TMGJMember ADD FExpiredDate DATETIME
ALTER TABLE TMGJMember ADD FCompId BIGINT
ALTER TABLE TMGJMember ADD FCardId BIGINT
ALTER TABLE TMGJMember ADD FMemo VARCHAR(1000)
ALTER TABLE TMGJMember ADD FArrear DECIMAL(18,6)
ALTER TABLE TMGJMember ADD FPoint DECIMAL(18,6)
ALTER TABLE TMGJMember ADD FBirthday DATETIME
ALTER TABLE TMGJMember ADD FBirthdayType CHAR
ALTER TABLE TMGJMember ADD FCustom1 VARCHAR(100)
ALTER TABLE TMGJCard ADD FMemId BIGINT
ALTER TABLE TMGJCard ADD FCardNo VARCHAR(50)
ALTER TABLE TMGJCard ADD FMemNo VARCHAR(50)
ALTER TABLE TMGJCard ADD FName VARCHAR(50)
ALTER TABLE TMGJCard ADD FGender INT
ALTER TABLE TMGJCard ADD FMobile VARCHAR(50)
ALTER TABLE TMGJCard ADD FCardTypeId BIGINT
ALTER TABLE TMGJCard ADD FCourseId BIGINT
ALTER TABLE TMGJCard ADD FBalance DECIMAL(18,6)
ALTER TABLE TMGJCard ADD FBalance2 DECIMAL(18,6)
ALTER TABLE TMGJCard ADD FRemainTimes INT
ALTER TABLE TMGJCard ADD FPurTimes INT
ALTER TABLE TMGJCard ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TMGJCard ADD FItemId BIGINT
ALTER TABLE TMGJCard ADD FCreateDate DATETIME
ALTER TABLE TMGJCard ADD FExpiredDate DATETIME
ALTER TABLE TMGJCard ADD FCompId BIGINT
ALTER TABLE TMGJCard ADD FCardId BIGINT
ALTER TABLE TMGJCard ADD FMemo VARCHAR(1000)
ALTER TABLE TMGJCard ADD FArrear DECIMAL(18,6)
ALTER TABLE TMGJCard ADD FPoint DECIMAL(18,6)
ALTER TABLE TMGJCard ADD FBirthday DATETIME
ALTER TABLE TMGJCard ADD FBirthdayType CHAR
ALTER TABLE TMGJCard ADD FCustom1 VARCHAR(100)
--<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FMemNo = B.cardNo
FROM TMGJMember AS A,TMgjCard AS B
WHERE A.Id = b.custId
UPDATE TMGJMember SET FMemId= NULL
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>ԱId
UPDATE A
SET A.FMemId = B.FMemId
FROM TMGJMember AS A,TMember_SD AS B
WHERE A.FMemNo = B.FMemNO
UPDATE TMGJMember SET FMemId= id WHERE FMemId Is null
UPDATE TMGJMember SET FName = name
UPDATE TMGJMember SET FCompId = 1
UPDATE TMGJMember SET FMobile = phone
UPDATE TMGJMember SET FGender = case when gender = 'F' then 0 else 1 end
UPDATE TMGJMember SET FCreateDate = DATEADD(second,cast(createtime as bigint) / 1000,'1970-01-01 00:00:00')
UPDATE TMGJMember SET FBirthday = DATEADD(second,cast(Birthday as bigint) / 1000,'1970-01-01 00:00:00')
UPDATE TMGJMember SET FBirthdayType = 'G'
--<EFBFBD><EFBFBD>
UPDATE TMGJCard SET FCardId = NULL
UPDATE A
SET A.FCardid = B.FCardid
FROM TMGJCard AS A,TMemberCard_SD AS B
WHERE A.cardNo = B.FCardNo
UPDATE TMGJCard SET FCardID = id WHERE FCardId IS NULL
UPDATE TMGJCard SET FCardNo = cardNO
UPDATE A
SET A.FMemId = B.FMemId
FROM TMGJCard AS A,TMGJMember AS B
WHERE A.custId = B.id
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FCardTypeId = C.FId
FROM TMGJCardType AS B,TMGJCard AS A,TMemberCardType AS C
WHERE A.cardTypeId = b.Id
AND b.cardCode = C.FNo
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE TMGJCard SET FBalance = balance
UPDATE TMGJCard SET FCompId = 1
UPDATE TMGJCard SET FCreateDate = DATEADD(second,cast(createtime as bigint) / 1000,'1970-01-01 00:00:00')
UPDATE TMGJCard SET FExpiredDate = DATEADD(year,100,FCreateDate)
SELECT * FROM TMGJCard
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,
FBirthdayType AS FBirthdayType,
FBirthday AS FBirthday,
'' AS FTelephone,
ISNULL(FMobile,'') AS FMobilePhone,
'' AS FQQ,
'' AS FWeChat,
'' AS FIdCard,
'' AS FEmail,
'' AS FAddress,
0 AS FProId,
'' AS FCPW,
'' AS FQPW,
0 AS FChargeEmpId,
ISNULL( FPoint,0) AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
ISNULL('','') AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TMGJMember
SELECT * FROM TMGJCard WHERE FMemId NOT IN(SELECT FMemId FROM TMember)
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,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
ISNULL(FRemainTimes,0) AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
ISNULL(FMemo,'' ) AS FMemo
FROM TMGJCard
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,0,FCreateDate,NULL AS FExpiredDate,''
FROM TMGJCard AS A
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(),'<EFBFBD><EFBFBD>ʢ<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>'
FROM TMGJCard AS A
SELECT FMemNo,SUM(1) FROM TMGJMember
GROUP BY FMemNo
ORDER BY SUM(1) DESC
SELECT * FROM TMGJMember WHERE FMemNo = '615'
SELECT * FROM TMGJCard WHERE cardNO = '615'
DELETE TMGJMember where id = 1909177
DELETE TMGJCard where custId = 1909177
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 id ,cardCode,cardName,1,2,price,0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
FROM TMGJCardType
WHERE cardCode = '99'
ORDER BY cardCode
SELECT * FROM TMemberCardType
DELETE TMemberCardType
SELECT * FROM
TMemberCardType AS A,TMGJCardType AS B
WHERE A.FNo = B.cardCode
AND A.FName != B.CardName
SELECT * FROM TMGJCard WHERE cardTypeId = 7520