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/导芮曼特/SQLQuery2.sql

489 lines
15 KiB

SELECT * FROM TMemberCardType
SELECT * FROM TMemberImport
SELECT * FROM TMemberImportEx
DELETE TMemberCardType WHERE FId > 0
INSERT INTO TMemberCardType(FId,FNo,FName,FValueType,FMaterial,FPrice,FCardFeeAmt,FAcctId,FDeposit,FAcctId2,FDeposit2,
FAcctId3,FDeposit3,FTimes,FAlertBalance,FMinRecharge,FPaySmsFee,FTimeCard,FValidityPeriod,FValidityPeriodUnit,FExpiredDate,
FDefaultMemo,FCreateTime,FAllowSale,FAllowRecharge,FAllowCross,FEnabled,FOrder,FDeptId)
SELECT dbo.FNNewId() AS FId,¿¨Ãû³Æ AS FNo,¿¨Ãû³Æ AS FName,1 AS ValueType,1 AS FMaterial,0 AS FPrice,0 AS FCardFeeAmt,0 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 FMinRecharge,0 AS FPaySmsFee,0 AS FTimeCard,0 AS FValidityPeriod,0 AS FValidityPeriodUnit,'' AS FExpiredDate,'' AS FDefaultMemo,'' AS FCreateTime,0 AS FAllowSale,0 AS FAllowRecharge,0 AS FAllowCross,1 AS FEnabled,0 AS FOrder,0 AS FDeptId
FROM TMemberImport
GROUP BY ¿¨Ãû³Æ
SELECT *INTO TMemberImport_Card FROM TMemberImport
DELETE TMemberImport
INSERT INTO TMemberImport(FId,FMemId,FMemNo,FCardId,FCardNo,FName,FGender,FMobilePhone,FCreateDate,FExpiredDate,FCardTypeId,FAcctId,FBalance,FAcctId2,FBalance2)
SELECT dbo.FNNewId(),dbo.FNNewId(),FCardNo,dbo.FNNewId(),FCardNo,FName, 0 ,ISNULL(FMobilePhone,''),FCreateDate, Dateadd(yy,100,FCreateDate),
0,0,0,0,0
FROM TMemberCourseImportEx
WHERE FCardNo NOT IN(select FNo FROM TMember)
GROUP BY FCardNo,FName,FMobilePhone,FCreateDate
SELECT * FROM TUser
SELECT * FROM TMemberCourseImportEx
WHERE FCourseNo NOT IN (SELECT FNo FROM TCourse)
order by FCardNo
ALTER TABLE TMemberCourseImportEx ADD FMemId BIGINT NOT NULL DEFAULT 0
ALTER TABLE TMemberCourseImportEx ADD FCourseId BIGINT NOT NULL DEFAULT 0
ALTER TABLE TMemberCourseImportEx ADD FId BIGINT NOT NULL DEFAULT 0
ALTER TABLE TMemberCourseImportEx ADD FItemId BIGINT NOT NULL DEFAULT 0
UPDATE TMemberCourseImportEx SET FId = dbo.FNNewId()
update A SET A.FMemId = B.FId
FROM TMemberCourseImportEx AS A,TMember AS B
WHERE A.FCardNo = B.FNo
update A SET A.FItemId = B.FItemId,
A.FCourseId = B.FId
FROM TMemberCourseImportEx AS A,TCourse AS B
WHERE A.FCourseNo = B.FNo
INSERT INTO TMemberImport(FId,FMemId,FMemNo,FCardId,FCardNo,FName,FGender,FMobilePhone,FCreateDate,FExpiredDate,FCardTypeId,FAcctId,FBalance,FAcctId2,FBalance2)
SELECT dbo.FNNewId(),dbo.FNNewId(),FCardNo,dbo.FNNewId(),FCardNo,FName, 0 ,FMobilePhone,FCreateDate, Dateadd(yy,100,FCreateDate),
(SELECT FId FROM TMemberCardType WHERE FNo=FCardTypeNo),3,FBalance,0,0
FROM TMemberImportEx
WHERE FMobilePhone IS NULL
SELECT * FROM TCompanY
SELECT FCardNo,SUM(1)
FROM TMemberCourseImportEx
GROUP BY FCardNo
SELECT * FROM TMemberCourseImportEx WHERE FRemainTimes IS NULL
sp_rename 'TMemberCourseImportEx$','TMemberCourseImportEx'
INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
SELECT FId,FMemId,FCourseId,0,FItemId,1,ISNULL(FRemainTimes,0),CASE WHEN ISNULL(FRemainTimes,0) = 0 THEN 0 ELSE FRemainAmount END,0,0,getdate(),null,'DR.Import',0,0,0,'Excelµ¼Èë',1,0
FROM TMemberCourseImportEx
UPDATE TMemberCourseImportEx SET FId = dbo.FNNewId()
INSERT INTO TMemberCourseHist(FId,FMemId,FMemCourseId,FPackId,FCourseId,FTime,FPurTimes,FFreeTimes,FUsePurTimes,FUseFreeTimes,
FPurAmount,FFreeAmount,FUsePurAmount,FUseFreeAmount,FCompId,
FBillType,FBizType,FTransId,FTransNo,FTransDetailId)
SELECT dbo.FNNewId(),FMemId,FId,0,FCourseId,FTime = getdate(),ISNULL(FRemainTimes,0),FFreeTimes = 0,0,0,
FPurAmount = CASE WHEN ISNULL(FRemainTimes,0) = 0 THEN 0 ELSE FRemainAmount END,0,0,0,1,
'DR','Import',0,'',0
FROM TMemberCourseImportEx
DELETE TMemberCardAcctHist
DELETE TMemberCardAccount
DELETE TMemberCard
DELETE TMember
INSERT INTO TMember(
FId,
FNo,
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 FId,
FMemNo AS FNo,
FName AS FName,
FBriefCode AS FBriefCode,
0 AS FTypeId,
FCompId AS FCompId,
FCreateDate AS FCreateDate,
FGender AS FGender,
FBirthdayType AS FBirthdayType,
FBirthday AS FBirthday,
FTelephone AS FTelephone,
FMobilePhone AS FMobilePhone,
'' AS FQQ,
'' AS FWeChat,
'' AS FIdCard,
'' AS FEmail,
'' AS FAddress,
0 AS FProId,
FPW AS FCPW,
'' AS FQPW,
0 AS FChargeEmpId,
0 AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
'' AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TMemberImport
INSERT INTO TMemberCard(
FId,
FNo,
FFaceNo,
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,
1 AS FCompId,
FMemId AS FMemId,
1 AS FState,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
FRemainTimes AS FTotalTimes,
0 AS FUsedTimes,
FCompId AS FSaleCompId,
0 AS FSaleBillId,
FMemo AS FMemo
FROM TMemberImport
INSERT TMemberCardAccount(FId,FCardId,FAcctId,FDeposit,FBalance,FArrear,FCreateDate,FExpiredDate,FMemo)
SELECT dbo.FNNewId(),FCardId AS FCardId,3,FBalance,FBalance,0,FCreateDate,FExpiredDate,FMemo
FROM TMemberImport
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,A.FAcctId,getdate(),A.FCardTypeId,A.FCompId,'DR','Import',0,'',A.FBalance,0,A.FBalance,0,getdate(),'´ÓExcelÖе¼Èë'
from TMemberImport AS A
INSERT TMemberOldTransHist(FId,FMemId,FTime,FCardId,FCompId,FBillType,FBizType,FTransNo,FContent,FPrice,FQuantity,FAmount,FPayment,FEmployee,FMemo)
SELECT dbo.FNNewId(),A.FId,xfrq,A.FId,A.FCompId,'DR','Import','','',cast(dzhje as decimal(18,6)),1,cast(dzhje as decimal(18,6)),'','',''
FROM xfxx,TMemberCard AS A
WHERE A.FNo = hykh
select * from xfxx2
update xfxx2 set hykh = 'A' + hykh
Truncate table TMemberOldTransHist
select * from xfxx
SELECT * FROM TMemberOld
select dateadd(yy,100,getdate())
UPDATE TMemberCard SET FExpiredDate = dateadd(yy,100,FCreateDate)
insert gcm12
(gcn00c,gcn01c,gcn02c,gcn09f,gcn10i,gcn12d,gcn13d,gcn15c,gcn17c,gcn22i,gcn24i,gcn04c,gcn06i,gcn03c,gcn16f)
select
'003',hykh,'0',knje,'0',jrrq,'22000101',hykh,'003','1','1',yddh,xb,hyxm,hyjf
from gcm12_01
UPDATE TMemberCard SET FCompId = (SELECT FId FROM TCompany WHERE FNo= '003')
UPDATE TMember SET FCompId = (SELECT FId FROM TCompany WHERE FNo= '003')
UPDATE TMemberCardAcctHist SET FCompId = (SELECT FId FROM TCompany WHERE FNo= '003')
SELECT * FROM TMemberSaleDetailPayment
SELECT FId,FNo INTO #Member FROM TMember WHERE FNo LIKE 'A%'
AND FCompId = 4734511574699135191
SELECT * FROM #Member
UPDATE #Member SET FNo = REPLACE(REPLACE(REPLACE(REPLACE( REPLACE( REPLACE(Replace(FNo,'£»',''),'£¿',''),'?',''),';',''),' ',''),'£º',''),'','')
UPDATE #Member SET FNo = REPLACE(FNo,'A','') WHERE FNo LIKE 'A%'
UPDATE #Member SET FNo = 'A' + FNo
WHERE FNo IN (SELECT FNo FROM TMember WHERE FCompId != 4734511574699135191)
SELECT * FROM #Member WHERE FNo like 'A%'
UPDATE B
SET B.FNo = 'A' + B.FNo
FROM #Member AS B,
(
SELECT FNo, COUNT(1) as cnt,max(FId) as FId FROM #Member
GROUP BY FNo
) AS A
WHERE cnt > 1
AND B.FId = A.FId
UPDATE A
SET A.FNo = B.FNo
FROM TMember AS A,#Member AS B
WHERE A.FId = B.FId
SELECT * FROM TMember WHERE FNo like 'A%'
UPDATE A
SET A.FNo = B.FNo,
A.FFaceNo = B.FNo
FROM TMemberCard AS A,TMember AS B
WHERE A.FId = B.FId
AND B.FCompId = 4734511574699135191
SELECT * FROM TMemberCard WHERE FNo like '%801127%'
SELECT * FROM TMemberCardType
UPDATE TMemberCardType SET FValidityPeriod = 1,FAllowRecharge = 1
UPDATE
UPDATE TMember SET FBriefCode = dbo.FNGetFirstPinYin(FName)
UPDATE TMemberCard SET FExpiredDate = DATEADD(yy,1,FCreateDate)
SELECT * FROM TImpMember WHERE µ±Ç°Ç·¿î is not null
drop table TImpMember
UPDATE TImpMember SET FMemId = dbo.FNNewId();
UPDATE TImpMember SET FCardId = dbo.FNNewId();
UPDATE TImpMember SET FName = »áÔ±ÐÕÃû,
FMobilePhone = ÊÖ»úºÅÂë,
FCardNo = »áÔ±¿¨ºÅ,
FMemNO = »áÔ±¿¨ºÅ,
FBalance =Óàî,
FPoint = µ±Ç°»ý·Ö,
FCreateDate = ISNULL(¿ª¿¨ÈÕÆÚ,getdate()),
FExpiredDate = DATEADD(year,1,ISNULL(¿ª¿¨ÈÕÆÚ,getdate()))
UPDATE TImpMember SET FMemNo = RIGHT('000' + FMemNo,4) WHERE LEN(FMemNo) < 4
UPDATE TImpMember SET FMemNo = FMobilePhone WHERE FMemNo IS NULL
UPDATE TImpMember SET FCardNo = FMemNo
SELECT * FROM TImpMember WHERE FCardTypeId IS NULL AND FCourseId IS NULL
UPDATE TImpMember SET FCardTypeId = (SELECT FId FROM TMemberCardType WHERE Fno = '5')
WHERE »áÔ±¿¨Ãû³Æ = '»áÔ±ÕÛ¿Û¿¨'
UPDATE TImpMember SET FCardTypeId = (SELECT FId FROM TMemberCardType WHERE Fno = '1')
WHERE »áÔ±¿¨Ãû³Æ = 'ÎåÕÛÄ꿨'
UPDATE TImpMember SET FCardTypeId = (SELECT FId FROM TMemberCardType WHERE Fno = '4')
WHERE »áÔ±¿¨Ãû³Æ = 'È«¼Ò¸£Ä꿨'
UPDATE TImpMember SET FCourseId = (SELECT FId FROM TCourse WHERE Fno = '1002L1')
WHERE »áÔ±¿¨Ãû³Æ = '¼ô·¢Ä꿨'
UPDATE TImpMember SET FCourseId = (SELECT FId FROM TCourse WHERE Fno = 'TRNKL1')
WHERE »áÔ±¿¨Ãû³Æ = 'ÌÌȾÄ꿨'
SELECT FMObilePhone ,FName,»áÔ±¿¨Ãû³Æ,SUM(1)
FROM TImpMember
GROUP BY FMObilePhone,FName,»áÔ±¿¨Ãû³Æ
ORDER BY SUM(1)DESC
SELECT FMemNo ,SUM(1)
FROM TImpMember
GROUP BY FMemNo
ORDER BY SUM(1)DESC
SELEC
UPDATE TImpMember SET FMemNo = '004' WHERE FName = 'ÎïÒµËνã'
SELECT * FROM TImpMember WHERE FMobilePhone = '18105399222'
SELECT * FROM TImpMember WHERE FMobilePhone = '18105399222'
SELECT * FROM TImpMember WHERE FMemNo = '0033'
DELETE TImpMember WHERE FMemNo = '0030' AND FMobilePhone = '18105399222'
DELETE TImpMember WHERE »áÔ±¿¨ºÅ IS NULL
SELECT * FROM TImpMemberEx
SELECT * FROM TImpMember
UPDATE A
SET A.FMemNo = B.FMemNo
FROM TImpMember AS A,TImpMemberEx AS B
WHERE A.FName = B.FName
AND A.FMobilePhone = B.FMobilePhone
AND A.»áÔ±¿¨Ãû³Æ= B.»áÔ±¿¨Ãû³Æ
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 FId,
FMemNo AS FNo,
ISNULL(FName,'') AS FName,
dbo.FNGetFirstPinYin(FName) AS FBriefCode,
0 AS FTypeId,
1 AS FCompId,
FCreateDate AS FCreateDate,
0 AS FGender,
'G' AS FBirthdayType,
NULL AS FBirthday,
'' AS FTelephone,
ISNULL( FMobilePhone,'') AS FMobilePhone,
'' AS FQQ,
'' AS FWeChat,
'' AS FIdCard,
'' AS FEmail,
'' AS FAddress,
0 AS FProId,
'' AS FCPW,
'' AS FQPW,
0 AS FChargeEmpId,
0 AS FPoint,
1 AS FRecvConsSMS,
1 AS FRecvBulkSMS,
'' AS FMemo,
'' AS FCustom1,'' AS FCustom2,'' AS FCustom3,'' AS FCustom4,'' AS FCustom5
from TIMpMember
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,
1 AS FCompId,
FMemId AS FMemId,
1 AS FState,
FCreateDate AS FCreateDate,
FExpiredDate AS FExpiredDate,
0 AS FTotalTimes,
0 AS FUsedTimes,
1 AS FSaleCompId,
0 AS FSaleBillId,
'' AS FMemo
FROM TImpMember
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,ISNULL(FBalance,0),ISNULL(FBalance,0),0,FCreateDate,FExpiredDate,''
FROM TImpMember
WHERE FCardTypeId 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,1,'DR','Import',0,'',ISNULL(FBalance,0),0,ISNULL(FBalance,0),0,getdate(),'´ÓExcelÖе¼Èë'
from TImpMember AS A
WHERE FCardTypeId IS NOT NULL
ALTER TABLE TImpMember ADD FDeleted BIT
ALTER TABLE TImpMember ADD FState INT
ALTER TABLE TImpMember ADD FMemId BIGINT
ALTER TABLE TImpMember ADD FCardId BIGINT
ALTER TABLE TImpMember ADD FMemNo VARCHAR(50)
ALTER TABLE TImpMember ADD FName VARCHAR(50)
ALTER TABLE TImpMember ADD FCardNo VARCHAR(50)
ALTER TABLE TImpMember ADD FMobilePhone VARCHAR(50)
ALTER TABLE TImpMember ADD FBirthday DATETIME
ALTER TABLE TImpMember ADD FBirthdayType CHAR
ALTER TABLE TImpMember ADD FCompId BIGINT
ALTER TABLE TImpMember ADD FMemo VARCHAR(2222)
ALTER TABLE TImpMember ADD FCreateDate DATETIME
ALTER TABLE TImpMember ADD FPoint DECIMAL(18,6)
ALTER TABLE TImpMember ADD FBalance DECIMAL(18,6)
ALTER TABLE TImpMember ADD FCardTypeId BIGINT
ALTER TABLE TImpMember ADD FCourseId BIGINT
ALTER TABLE TImpMember ADD FItemId BIGINT
ALTER TABLE TImpMember ADD FExpiredDate DATETIME
ALTER TABLE TImpMember DROP COLUMN FExpiredDate
S
INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice)
SELECT FCardId,FMemId,FCourseId,0,FItemId,1,0,0,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,'',2,0
FROM TImpMember
WHERE 1=1
-- AND FDeleted = 0
AND FCourseId IS NOT NULL
UPDATE A
SET A.FItemId = B.FItemId
FROM TImpMember AS A,TCOurse AS B
WHERE A.FCOurseId = B.FId
INSERT INTO TMemberCourseHist(FId,FMemId,FMemCourseId,FPackId,FCourseId,FTime,FPurTimes,FFreeTimes,FUsePurTimes,FUseFreeTimes,
FPurAmount,FFreeAmount,FUsePurAmount,FUseFreeAmount,FCompId,
FBillType,FBizType,FTransId,FTransNo,FTransDetailId)
SELECT dbo.FNNewId(),FMemId,FCardId,0,FCourseId,FTime = getdate(),0,0,0,0,
0,0,0,0,1,
'DR','Import',0,'',0
FROM TImpMember
WHERE 1=1
-- AND FDeleted = 0
AND FCourseId IS NOT NULL
SELECT FMemNo FROM TMember
UPDATE TPayAccount SET FName = 'Ä꿨/ÁƳÌ' WHERE FId = 6