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/爱尚(焦作)/SQLQuery12.sql

421 lines
13 KiB

SELECT * FROM TImpMember
DROP TABLE TImpCardType
CREATE TABLE TImpCardType
(
FId BIGINT,
FNo VARCHAR(20),
FName VARCHAR(30),
FType VARCHAR(30),
FValueType INT
)
INSERT TImpCardType
SELECT dbo.FNNewId(),CardName + '[' + CAST(Discount AS VARCHAR) + '折]',
CardName + '[' + CAST(Discount AS VARCHAR) + '折]',
CardTypeName,CASE WHEN CardTypeName = '计次消费' THEN 3 ELSE 1 END FROM TImpMember
WHERE CardName IS NOT NULL
GROUP BY CardName + '[' + CAST(Discount AS VARCHAR) + '折]',CardTypeName
SELECT * FROM TImpMember WHERE CardName IS NULL
ALTER TABLE TImpMember ADD FMemId BIGINT
ALTER TABLE TImpMember ADD FCardNo VARCHAR(50)
ALTER TABLE TImpMember ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMember ADD FName VARCHAR(50)
ALTER TABLE TImpMember ADD FGender INT
ALTER TABLE TImpMember ADD FMobile VARCHAR(50)
ALTER TABLE TImpMember ADD FCardTypeId BIGINT
ALTER TABLE TImpMember ADD FCourseId BIGINT
ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMember ADD FBalance2 DECIMAL(18,6)
ALTER TABLE TImpMember ADD FRemainTimes INT
ALTER TABLE TImpMember ADD FPurTimes INT
ALTER TABLE TImpMember ADD FPurAmount DECIMAL(18,6)
ALTER TABLE TImpMember ADD FItemId BIGINT
ALTER TABLE TImpMember ADD FCreateDate DATETIME
ALTER TABLE TImpMember ADD FExpiredDate DATETIME
ALTER TABLE TImpMember ADD FCompId BIGINT
ALTER TABLE TImpMember ADD FCardId BIGINT
ALTER TABLE TImpMember ADD FMemo VARCHAR(1000)
ALTER TABLE TImpMember ADD FArrear DECIMAL(18,6)
ALTER TABLE TImpMember ADD FPoint DECIMAL(18,6)
ALTER TABLE TImpMember ADD FBirthday DATETIME
ALTER TABLE TImpMember ADD FBirthdayType CHAR
ALTER TABLE TImpMember ADD FCustom1 VARCHAR(100)
SELECT * FROM TImpMember WHERE ID = 23807199
SELECT * FROM TImpMember WHERE = '13838316783'
UPDATE TImpMember SET FMemId = MemId
UPDATE TImpMember SET FCardId = CardId
UPDATE TImpMember SET FCardNo = CardNo
UPDATE TImpMember SET FMemNo = CardNo
UPDATE TImpMember SET FName = Name
UPDATE TImpMember SET FMobile = MobilePhone
UPDATE TImpMember SET FGender = CASE WHEN Gender = '' THEN 1 ELSE '0' END
UPDATE TImpMember SET FCreateDate = CreateDate
UPDATE TImpMember SET FExpiredDate = DATEADD(YEAR,100,CreateDate)
UPDATE TImpMember SET FArrear =
UPDATE TImpMember SET FMemo =
SELECT * FROM TImpMember WHERE FMemo != ''
ALTER TABLE TImpMember ADD FPointText VARCHAR(100)
UPDATE TImpMember SET FPointText = replace(replace(replace(replace(,'',''),char(10),''),char(13),''),' ','')
UPDATE TImpMember SET FPoint = CAST(FPointText AS FLOAT)
SELECT FROM TImpMember WHERE NOT LIKE '%分%'
UPDATE TImpMember SET FCompId = dbo.FNCompId('002')
SELECT FROM TImpMember
UPDATE TImpMember SET FMemo = FMemo + '【华山路店】' WHERE ID = 130011
UPDATE TImpMember SET FMemo = FMemo + '【经五路店】' WHERE ID = 130012
UPDATE TImpMember SET FMemo = FMemo + '【园田路店】' WHERE ID = 130013
UPDATE TImpMember SET FMemo = FMemo + '【经三路店】' WHERE ID = 130016
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMember AS A,TImpCardType AS B
WHERE A.CardName + '[' + CAST(Discount AS VARCHAR) + '折]' = B.FName
UPDATE TImpMember SET FExpiredDate = DATEADD(YEAR,100,FCreateDate)
WHERE FExpiredDate IS NULL
SELECT * FROM TImpMember WHERE FCreateDate IS NULL
UPDATE TImpMember SET FBirthdayType = 'G'
UPDATE TImpMember SET FBirthdayType = 'L' WHERE LIKE '%农历%'
UPDATE TImpMember SET FBirthday = REPLACE(REPLACE( , '农历','9999-') , '阳历','9999-')
SELECT * FROM TImpMember WHERE FMemId = 6273693882209312287
UPDATE TImpMember SET FCardNo = + '.2' ,FMemNo = + '.2'
WHERE FMemId = 8349508648302214543
UPDATE TImpMember SET FMemId = 6273693882209312287 WHERE FMemId = 8349508648302214543
SELECT * FROM TImpMember WHERE FMobile = '15039585857'
--
SELECT * FROM TImpMember WHERE CardTypeName = '计次消费'
UPDATE TImpMember SET Balance = REPLACE(REPLACE( REPLACE(Balance,char(10),''),char(13),''),' ','')
UPDATE TImpMember SET FRemainTimes = REPLACE(SUBSTRING(Balance,CHARINDEX('余:',Balance) + 2,LEN(Balance)),'','')
FROM TImpMember WHERE CardTypeName = '计次消费'
UPDATE TImpMember SET FBalance = CAST(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
LEFT(Balance,CHARINDEX('',Balance) + 3),'',''),
' ','') ,
char(10),''),
'疗程','')
AS float)
UPDATE TImpMember SET FBalance2 = CAST(REPLACE( REPLACE(REPLACE(REPLACE(LEFT(,CHARINDEX('',) + 3),'',''),' ','') ,char(10),''),' ','')
AS float)
----------
SELECT CardNO,CAST(REPLACE( REPLACE(REPLACE(REPLACE(LEFT(Balance,CHARINDEX('',Balance) + 3),'',''),' ','') ,char(10),''),' ','')
AS float)
FROM TImpMember
WHERE CardNO > '11616'
ORDER BY CardNO ASC
SELECT REPLACE( REPLACE(REPLACE(REPLACE(LEFT(Balance,CHARINDEX('',Balance) + 3),'',''),' ','') ,char(10),''),' ','') FROM TImpMember WHERE CardNO > '11616'
ORDER BY CardNO ASC
ALTER TABLE TImpMember ADD FSeq INT IDENTITY
ALTER TABLE TImpMember ADD FIndex INT
UPDATE A
SET A.FIndex = 1+(SELECT COUNT(1) FROM TImpMember AS B WHERE A.FCardNo = B.FCardNo AND ( ( A.FSeq > B.FSeq) ))
FROM TImpMember AS A
SELECT A.FCardNO, 1+(SELECT COUNT(1) FROM TImpMember AS B WHERE A.FCardNo = B.FCardNo AND ( ( A.FSeq > B.FSeq) ))
FROM TImpMember AS A
WHERE FCardNO = '12150'
SELECT * FROM TImpMember WHERE FIndex > 1 AND FCardno = '12150'
UPDATE TImpMember SET FCardNO = REPLACE(FCardNO,'.1','')
UPDATE TImpMember SET FCardNO = REPLACE(FCardNO,'.2','')
UPDATE TImpMember SET FCardNo = FCardNo + '.' + CAST(FIndex AS VARCHAR) WHERE FCardNo IN(SELECT FCardNo FROM TImpMember WHERE FIndex > 1)
UPDATE TImpMember SET FMemNo = FCardNo
UPDATE TImpMember SET FMemNo = FMobile WHERE FMemNO IS NULL
SELECT * FROM TImpMember
UPDATE A
SET A.FMemNo = B.FMemNo
FROM TImpMember AS A,TImpMember AS B
WHERE A.FMemId = B.FMemId
AND A.FIndex > 1
AND B.FIndex = 1
SELECT * FROM TImpMember AS A WHERE 1=1
AND A.FMemId IN(
select FMemId from TImpMember
GROUP BY FMemId
HAVING(SUM(1) > 1)
)
SELECT * FROM TImpmEMBER WHERE FCardNO = '12150'
SELECT FCardNo,SUM(1) AS Cnt FROM TImpMember
GROUP BY FCardNo
ORDER BY SUM(1) DESC
SELECT FMemNo,FMobile,SUM(1) AS Cnt FROM TImpMember
GROUP BY FMemNo ,FMobile
ORDER BY SUM(1) DESC
SELECT * FROM TImpMember WHERE FIndex = 0 ORDER BY FIndex DESC
SELECT FMemNo,SUM(1) AS Cnt FROM TImpMember
GROUP BY FMemNo
ORDER BY SUM(1) DESC
UPDATE A
SET A.FCardNo = A.FMobile,
A.FMemno = A.FMobile
from TImpMember AS A
WHERE FMemNo IN
(
SELECT FMemNo FROM (
SELECT FMemNo,SUM(1) AS Cnt FROM TImpMember
GROUP BY FMemNo
) AS T
WHERE T.Cnt > 1
)
SELECT * FROM TImpMember WHERE FMemno = '10839'
delete TMemberCardType WHERE FId > 100
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 ,FNo,FName,FValueType,2,0,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 TImpCardType
ORDER BY FNo
UPDATE TMemberCardType SET FAllowRchg = 1
UPDATE TMemberCardType SET FAllowSale = 1
UPDATE TMemberCardType SET FEnabled = 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 = dbo.FNCompId('002')
AND NOT EXISTS(SELECT TOP 1 1 FROM TMemberCardTypeSub AS B WHERE B.FCompId = C.FId AND B.FCardTypeId = I.FId)
AND I.FId IN(SELECT FId FROM TImpCardType)
UPDATE A
SET A.FCardTypeId = B.FId
FROM TImpMember AS A,TMemberCardType AS B
WHERE A.
DELETE TImpCardType WHERE FId = 7976813579673386319
DELETE TImpCardType WHERE FId = 9112300963023479389
SELECT * FROM TImpMember WHERE = '完美剪发年卡'
SELECT * FROM TImpMember WHERE = ''
SELECT * FROM TImpCardType WHERE FNo = '完美剪发年卡'
UPDATE TImpMember SET = '未知' WHERE = ''
UPDATE TImpCardType SET FNo = '未知' ,FName = '未知' WHERE FNo = ''
UPDATE TMemberCardType SET FMaterial = 2
SELECT * FROM TMemberCardType
UPDATE A
SET A.FValueType = 3
FROM TMemberCardType AS A,TImpCardType AS B
WHERE A.FId = B.FId
UPDATE TImpMember SET FMemNO = 'A' + FMemNo,FCardNo = 'A' + FCardNO
WHERE FCardNO IN(SELECT FCardNo FROM TMemberCard)
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 TImpMember
GROUP BY FMemId,FMemNo,FName,FMobile,FGender,FCompId,FBirthdayType,FBirthday,FCreateDate,FPoint
/*
SELECT * FROM TImpMember
WHERE FMemId IN(
SELECT FMemId,FMemNo,FName,FMobile,FGender,FCompId ,FBirthdayType ,FBirthday,FCreateDate,FPoint
INTO #Temp
FROM TImpMember
GROUP BY FMemId,FMemNo,FName,FMobile,FGender,FCompId ,FBirthdayType ,FBirthday,FCreateDate,FPoint
ORDER BY SUM(1) DESC
)
SELECT FMemId
FROM #Temp
GROUP BY FMemId
HAVING(SUM(1)) > 1
SELECT * FROM TImpmEMBER WHERE FMemId = 25006217
UPDATE TImpMember SET FMemNo = '0000330' WHERE FMemId = 25463627
UPDATE TImpMember SET FMemNo = '0000055' WHERE FMemId = 25006217
*/
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 TImpMember
WHERE FCardId 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,NULL AS FExpiredDate,''
FROM TImpMember AS A
WHERE FCardId IS NOT NULL
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(),'从盛传中导入'
FROM TImpMember AS A
WHERE FCardId IS NOT NULL
INSERT TMemberCardAccount(FMemId,FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT FMemId,dbo.FNNewId(),FCardId AS FCardId,10,FBalance2,FBalance2,0,FCreateDate,NULL AS FExpiredDate,''
FROM TImpMember AS A
WHERE FBalance2 != 0
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,10,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance2,0,A.FBalance2,0,getdate(),'从盛传中导入'
FROM TImpMember AS A
WHERE FBalance2 != 0
SELECT * FROM TImpMember AS A
WHERE FBalance2 != 0
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)
SELECT * FROM TMemberCard WHERE FMemo != ''
SELECT * FROM TImpMember where != ''