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/琦佳会员统计.sql

1358 lines
62 KiB

1 year ago
alter PROCEDURE PRptMemberReport
(
@IParam VARCHAR(8000) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
)
AS
BEGIN
-- exec PDropTempTables
--IF object_id('#Member') IS NOT NULL
--BEGIN
-- DROP TABLE #Member
--END
SELECT @IParam = dbo.FNToDBC(@IParam)
CREATE TABLE #Member
(
--FSId INT NOT NULL,
FCompId BIGINT NOT NULL,
FMemId BIGINT NOT NULL,
FMemNo VARCHAR(50) NOT NULL, --<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FName VARCHAR(80) NOT NULL, --<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FCompNo VARCHAR(60) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾
FGender INT NOT NULL, --<EFBFBD>Ա<EFBFBD>
FMobilePhone VARCHAR(50) NOT NULL, --<EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FBirthday VARCHAR(30) NULL, -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FBirthdayType CHAR NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FJoinDate VARCHAR(30) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FIsVisitor BIT,--ɢ<EFBFBD><EFBFBD>
FRchgAmt DECIMAL(18,6) NOT NULL DEFAULT 0, --<EFBFBD>ۼƳ<EFBFBD>ֵ
FConsAmt DECIMAL(18,6) NOT NULL DEFAULT 0, --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FCardConsAmt DECIMAL(18,6) NOT NULL DEFAULT 0, --<EFBFBD>ۼƴ<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FConsTimes INT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>
FLastDate VARCHAR(20) NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FPoint DECIMAL(18,6) NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FArrear DECIMAL(18,6) NOT NULL DEFAULT 0, --Ƿ<EFBFBD><EFBFBD>
FConsArrear DECIMAL(18,6) NOT NULL DEFAULT 0,--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>
FConsPrice DECIMAL(18,6) NOT NULL DEFAULT 0,
FCourseArrear DECIMAL(18,6) NOT NULL DEFAULT 0,
FFavoriteEmpName VARCHAR(100), --ϲ<EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD>ʦ
FSaleEmpName VARCHAR(100), --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FChargeEmpId BIGINT, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>
FMemMemo VARCHAR(1000), --<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ע
PRIMARY KEY(FMemId)
)
--=IF object_id('dbo.#MemberCard') IS NOT NULL
--BEGIN
-- DROP TABLE #MemberCard
--END
CREATE TABLE #MemberCard
(
-- FSId INT NOT NULL, --<EFBFBD><EFBFBD>¼id
FCardKind VARCHAR(50) ,
FCardId BIGINT NOT NULL, --<EFBFBD><EFBFBD>Id
FCardNo VARCHAR(50) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FMemId BIGINT NOT NULL, --<EFBFBD><EFBFBD>ԱId
FMemNo VARCHAR(50) NOT NULL, --<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FCompId BIGINT NOT NULL, --<EFBFBD><EFBFBD>˾Id
FCardTypeId BIGINT NOT NULL,
FCardTypeNo VARCHAR(1000) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FCardTypeName VARCHAR(100) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FCreateDate VARCHAR(20) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FExpiredDate VARCHAR(20) NULL, --<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>
FPurAmount DECIMAL(18,6), --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FRemainTimes INT, --ʣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FRemainPurAmount DECIMAL(18,6) , --ʣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FRemainFreeAmount DECIMAL(18,6) , --ʣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FState INT, --״̬
FCalcMode INT DEFAULT 1,
FItemId BIGINT DEFAULT 0,
FCardMemo VARCHAR(1000), --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע
FRchgAmt DECIMAL(18,6) NOT NULL DEFAULT 0, --<EFBFBD>ۼƳ<EFBFBD>ֵ
FConsAmt DECIMAL(18,6) NOT NULL DEFAULT 0, --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FCardConsAmt DECIMAL(18,6) NOT NULL DEFAULT 0, --<EFBFBD>ۼƴ<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FConsTimes INT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>
FLastDate VARCHAR(20) NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FBizEmpId BIGINT, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
FBizEmpName VARCHAR(100), --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
PRIMARY KEY(FCardId,FCardKind)
)
CREATE TABLE #MemberCardAccount
(
FMemId BIGINT,
FCardId BIGINT,
FAcctId BIGINT,
FBalance DECIMAL(18,6),
FArrear DECIMAL(18,6)
)
DECLARE @SId INT
DECLARE @CompanyForCard BIT --ʹ<EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾
DECLARE @MemCompNo VARCHAR(1000) --<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>˾
DECLARE @CompSource INT --<EFBFBD><EFBFBD>˾
DECLARE @ShowCardInfo BIT --<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>
DECLARE @ShowCourseInfo INT --<EFBFBD><EFBFBD>ʾ<EFBFBD>Ƴ<EFBFBD>
-- DECLARE @CardCompNo VARCHAR(1000)--<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾
DECLARE @CompanyStr VARCHAR(1000)--<EFBFBD><EFBFBD>˾
DECLARE @FromMemNo VARCHAR(30) --<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToMemNo VARCHAR(30) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @MemName VARCHAR(50) --<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @MobilePhone VARCHAR(20) --<EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @FromBirthday VARCHAR(20)--<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1-0121
DECLARE @ToBirthday VARCHAR(20) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1-0212
DECLARE @FromJoinDate DATETIME --<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToJoinDate DATETIME --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @Gender INT --<EFBFBD>Ա<EFBFBD>
DECLARE @FromPoint DECIMAL(18,6) --<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToPoint DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @FromArrear DECIMAL(18,6) --<EFBFBD><EFBFBD>ʼǷ<EFBFBD><EFBFBD>
DECLARE @ToArrear DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>
DECLARE @FromLastDate VARCHAR(20)--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToLastDate VARCHAR(20) --
DECLARE @AfterLastDate VARCHAR(20) --
DECLARE @FromConsTimes INT --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToConsTimes INT
DECLARE @FromConsAmt DECIMAL(18,6)--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܶ<EFBFBD>
DECLARE @ToConsAmt DECIMAL(18,6) --
DECLARE @FromRchgAmt DECIMAL(18,6)
DECLARE @ToRchgAmt DECIMAL(18,6)
DECLARE @NotComeDay INT --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @FromStatDate VARCHAR(20) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToStatDate VARCHAR(20) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ShowCardConsAmt BIT
DECLARE @FromCardNo VARCHAR(30) --<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToCardNo VARCHAR(30) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @CardTypeNo VARCHAR(1000)
DECLARE @FromCardCreateDate DATETIME --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToCardCreateDate DATETIME
DECLARE @FromCardExpiredDate DATETIME --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToCardExpiredDate DATETIME --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @FromAcctExpiredDate DATETIME --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToAcctExpiredDate DATETIME --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @FromRemainTimes DECIMAL(18,6) --ʣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToRemainTimes DECIMAL(18,6) --ʣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @CardState INT --<EFBFBD><EFBFBD>״̬
DECLARE @AcctNo VARCHAR(30) --<EFBFBD>˻<EFBFBD>
DECLARE @FromBalance DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToBalance DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @CardExpired INT --<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1<EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>0ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @BalanceCutDate VARCHAR(20) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @BizEmpNo VARCHAR(1000) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
DECLARE @FavoriteEmpNo VARCHAR(1000) --ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>
DECLARE @FavoriteEmpId BIGINT --ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>
DECLARE @BizEmpId BIGINT
DECLARE @ShowAllMember BIT
DECLARE @IsVisitor BIT
--<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @CourseNo VARCHAR(1000)
DECLARE @FromCourseRemainTimes DECIMAL(18,6)
DECLARE @ToCourseRemainTimes DECIMAL(18,6)
DECLARE @FromCardPurAmount DECIMAL(18,6) --<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>۽<EFBFBD><EFBFBD><EFBFBD>
DECLARE @ToCardPurAmount DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>۽<EFBFBD><EFBFBD><EFBFBD>
SELECT @MemCompNo = dbo.FNGetParamValue(@IParam,'CompNo');
SELECT @CompSource = dbo.FNGetParamValue(@IParam,'CompSource');
--SELECT @CardCompNo = dbo.FNGetParamValue(@IParam,'CardCompNo');
--SELECT @SId = dbo.FNGetParamValue(@IParam,'SId');
SELECT @ShowCardInfo = ISNULL(dbo.FNGetParamValue(@IParam,'ShowCardInfo'),1);
SELECT @ShowCourseInfo = ISNULL(dbo.FNGetParamValue(@IParam,'ShowCourseInfo'),0);
SELECT @FromMemNo = ISNULL(dbo.FNGetParamValue(@IParam,'FromMemNo'),'');
SELECT @ToMemNo = ISNULL(dbo.FNGetParamValue(@IParam,'ToMemNo'),'');
SELECT @MemName = ISNULL(dbo.FNGetParamValue(@IParam,'MemName'),'');
SELECT @MobilePhone = ISNULL(dbo.FNGetParamValue(@IParam,'MobilePhone'),'');
SELECT @Gender = ISNULL(dbo.FNGetParamValue(@IParam,'Gender'),-1);
SELECT @FromBirthday = ISNULL(dbo.FNGetParamValue(@IParam,'FromBirthday'),'');
SELECT @ToBirthday = ISNULL(dbo.FNGetParamValue(@IParam,'ToBirthday'),'');
SELECT @FromJoinDate = dbo.FNGetParamValue(@IParam,'FromJoinDate');
SELECT @ToJoinDate = dbo.FNGetParamValue(@IParam,'ToJoinDate');
SELECT @FromPoint = ISNULL( dbo.FNGetParamValue(@IParam,'FromPoint'),0);
SELECT @ToPoint = ISNULL(dbo.FNGetParamValue(@IParam,'ToPoint'),0);
SELECT @FromArrear = ISNULL( dbo.FNGetParamValue(@IParam,'FromArrear'),0);
SELECT @ToArrear = ISNULL(dbo.FNGetParamValue(@IParam,'ToArrear'),0);
SELECT @FromLastDate = ISNULL( dbo.FNGetParamValue(@IParam,'FromLastDate'),'');
SELECT @ToLastDate = ISNULL(dbo.FNGetParamValue(@IParam,'ToLastDate'),'');
SELECT @AfterLastDate = ISNULL(dbo.FNGetParamValue(@IParam,'AfterLastDate'),'');
SELECT @FromConsTimes = ISNULL( dbo.FNGetParamValue(@IParam,'FromConsTimes'),NULL);
SELECT @ToConsTimes = ISNULL(dbo.FNGetParamValue(@IParam,'ToConsTimes'),NULL);
SELECT @FromConsAmt = ISNULL( dbo.FNGetParamValue(@IParam,'FromConsAmt'),NULL);
SELECT @ToConsAmt = ISNULL(dbo.FNGetParamValue(@IParam,'ToConsAmt'),NULL);
SELECT @FromRchgAmt = ISNULL( dbo.FNGetParamValue(@IParam,'FromRchgAmt'),NULL);
SELECT @ToRchgAmt = ISNULL(dbo.FNGetParamValue(@IParam,'ToRchgAmt'),NULL);
SELECT @NotComeDay = ISNULL(dbo.FNGetParamValue(@IParam,'NotComeDay'),0);
SELECT @ShowCardConsAmt = ISNULL(dbo.FNGetParamValue(@IParam,'ShowCardConsAmt'),0)
SELECT @FromStatDate = ISNULL(dbo.FNGetParamValue(@IParam,'FromStatDate'),'');
SELECT @ToStatDate = ISNULL(dbo.FNGetParamValue(@IParam,'ToStatDate'),'');
SELECT @FromCardNo = ISNULL(dbo.FNGetParamValue(@IParam,'FromCardNo'),'');
SELECT @ToCardNo = ISNULL(dbo.FNGetParamValue(@IParam,'ToCardNo'),'');
SELECT @CardState = ISNULL(dbo.FNGetParamValue(@IParam,'CardState'),0);
SELECT @CardTypeNo = ISNULL(dbo.FNGetParamValue(@IParam,'CardTypeNo'),'');
SELECT @FromCardCreateDate = ISNULL(dbo.FNGetParamValue(@IParam,'FromCardCreateDate'),NULL);
SELECT @ToCardCreateDate = ISNULL(dbo.FNGetParamValue(@IParam,'ToCardCreateDate'),NULL);
SELECT @FromCardExpiredDate = ISNULL(dbo.FNGetParamValue(@IParam,'FromCardExpiredDate'),NULL);
SELECT @ToCardExpiredDate = ISNULL(dbo.FNGetParamValue(@IParam,'ToCardExpiredDate'),NULL);
SELECT @FromAcctExpiredDate = ISNULL(dbo.FNGetParamValue(@IParam,'FromAcctExpiredDate'),NULL);
SELECT @ToAcctExpiredDate = ISNULL(dbo.FNGetParamValue(@IParam,'ToAcctExpiredDate'),NULL);
SELECT @FromRemainTimes = ISNULL(dbo.FNGetParamValue(@IParam,'FromCourseRemainTimes'),0);
SELECT @ToRemainTimes = ISNULL(dbo.FNGetParamValue(@IParam,'ToCourseRemainTimes'),0);
SELECT @FromBalance = ISNULL(dbo.FNGetParamValue(@IParam,'FromBalance'),0);
SELECT @ToBalance = ISNULL(dbo.FNGetParamValue(@IParam,'ToBalance'),0);
SELECT @AcctNo = ISNULL(dbo.FNGetParamValue(@IParam,'AcctNo'),'');
SELECT @CardExpired = ISNULL(dbo.FNGetParamValue(@IParam,'CardExpired'),0);
SELECT @BalanceCutDate = ISNULL(dbo.FNGetParamValue(@IParam,'BalanceCutDate'),'');
SELECT @BizEmpNo = ISNULL(ISNULL(dbo.FNGetParamValue(@IParam,'BizEmpNo'), dbo.FNGetParamValue(@IParam,'ChargeEmpNo')),'');
SELECT @FavoriteEmpNo = ISNULL(dbo.FNGetParamValue(@IParam,'FavoriteEmpNo'),'');
SELECT @ShowAllMember = ISNULL(dbo.FNGetParamValue(@IParam,'ShowAllMember'),1);
SELECT @IsVisitor = ISNULL(dbo.FNGetParamValue(@IParam,'IsVisitor'),0);
SELECT @FromCourseRemainTimes = ISNULL(dbo.FNGetParamValue(@IParam,'FromCourseRemainTimes'),0);
SELECT @ToCourseRemainTimes = ISNULL(dbo.FNGetParamValue(@IParam,'ToCourseRemainTimes'),0);
SELECT @CourseNo = ISNULL(dbo.FNGetParamValue(@IParam,'CourseNo'),'');
SELECT @FromCardPurAmount = ISNULL(dbo.FNGetParamValue(@IParam,'FromCardPurAmount'),'0');
SELECT @ToCardPurAmount = ISNULL(dbo.FNGetParamValue(@IParam,'ToCardPurAmount'),'0');
CREATE TABLE #MemCompIds
(
FCompId BIGINT
)
/* DECLARE @CardCompIds TABLE
(
FCompId BIGINT
) */
CREATE TABLE #CardTypeIds
(
FCardTypeId BIGINT
)
CREATE TABLE #CourseIds
(
FCourseId BIGINT
)
IF @MemCompNo = ''-- AND @CardCompNo = ''
BEGIN
RETURN
END
--<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>˾
IF @MemCompNo = 'All' OR @MemCompNo = ''
BEGIN
INSERT #MemCompIds
SELECT FId FROM TCompany
END
ELSE
BEGIN
INSERT #MemCompIds
SELECT A.FId
FROM TCompany AS A WITH(NOLOCK), dbo.FNStrSplit(@MemCompNo) AS B
WHERE A.FNo = B.Field
END
--<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF @CardTypeNo != ''
BEGIN
INSERT #CardTypeIds
SELECT FId FROM TMemberCardType WITH(NOLOCK)
WHERE FNo IN (SELECT Field FROM dbo.FNStrSplit( @CardTypeNo))
END
IF @CourseNo != ''
BEGIN
INSERT #CourseIds
SELECT FId FROM TCourse WITH(NOLOCK)
WHERE FNo IN(SELECT Field FROM dbo.FNStrSplit(@CourseNo))
END
IF @FromCardCreateDate IS NOT NULL
BEGIN
SELECT @FromCardCreateDate = @FromCardCreateDate + ' 00:00:00'
SELECT @ToCardCreateDate = @ToCardCreateDate + ' 23:59:59'
END
IF @FromCardExpiredDate IS NOT NULL
BEGIN
SELECT @FromCardExpiredDate = @FromCardExpiredDate + ' 00:00:00'
SELECT @ToCardExpiredDate = @ToCardExpiredDate + ' 23:59:59'
END
IF @FromAcctExpiredDate IS NOT NULL
BEGIN
SELECT @FromAcctExpiredDate = @FromAcctExpiredDate + ' 00:00:00'
SELECT @ToAcctExpiredDate = @ToAcctExpiredDate + ' 23:59:59'
END
IF ISNULL(@ToStatDate,'') != ''
BEGIN
SELECT @FromStatDate = @FromStatDate + ' 00:00:00'
SELECT @ToStatDate = @ToStatDate + ' 23:59:59'
END
IF ISNULL(@ToJoinDate,'') != ''
BEGIN
SELECT @FromJoinDate = @FromJoinDate + ' 00:00:00'
SELECT @ToJoinDate = @ToJoinDate + ' 23:59:59'
END
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DECLARE @Today DATETIME
SELECT @Today = CONVERT(varchar(100), GETDATE(), 23)
SELECT @BizEmpId = 0
IF @BizEmpNo != ''
BEGIN
SELECT @BizEmpId = FId FROM TEmployee WHERE FNo = @BizEmpNo
END
SELECT @FavoriteEmpId = 0
IF @FavoriteEmpNo != ''
BEGIN
SELECT @FavoriteEmpId = FId FROM TEmployee WHERE FNo = @FavoriteEmpNo
END
SELECT @FromBirthday = REPLACE(@FromBirthday,'1-','G-'),
@ToBirthday = REPLACE(@ToBirthday,'1-','G-'),
@FromBirthday = REPLACE(@FromBirthday,'2-','L-'),
@ToBirthday = REPLACE(@ToBirthday,'2-','L-')
--<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>
DECLARE @InsertMember VARCHAR(8000)
DECLARE @InsertCard VARCHAR(8000)
DECLARE @InsertCourse VARCHAR(8000)
DECLARE @MemberWhere VARCHAR(8000)
DECLARE @CardWhere VARCHAR(8000)
DECLARE @CourseWhere VARCHAR(8000)
DECLARE @CardParam NVARCHAR(4000)
DECLARE @MemParam NVARCHAR(4000)
DECLARE @CourseParam NVARCHAR(4000)
SELECT @InsertMember = 'INSERT #Member(FCompId,FCompNo, FMemId,FMemNo,FName,FGender,FMobilePhone,FJoinDate,FIsVisitor,FBirthday,FBirthdayType,FPoint,FChargeEmpId,FSaleEmpName,FMemMemo,FLastDate,FConsTimes,FConsAmt,FRchgAmt)'
+ ' SELECT A.FCompId,'''' AS FCompNo,FMemId AS FMemId, FMemNo AS FMemNo,A.FName AS FName,A.FGender,A.FMobilePhone,CONVERT(varchar(10),A.FCreateDate,23) AS FJoinDate,A.FIsVisitor, '
+ ' ISNULL(CONVERT(varchar(10), A.FBirthday, 23),'''') AS FBirthday,A.FBirthdayType,FPoint,FChargeEmpId,'''' AS FSaleEmpName,A.FMemo,'
+ ' CAST('''' AS VARCHAR(10)) AS FLastDate,'
+ ' CAST(0 AS INT) AS FConsTimes,'
+ ' CAST(0 AS DECIMAL(18,6)) AS FConsAmt,'
+ ' CAST(0 AS DECIMAL(18,6)) AS FRchgAmt'
+ ' FROM TMember AS A WITH(NOLOCK)'
SELECT @MemberWhere = ' WHERE 1=1'
+ ' AND A.FMemId > 99'
+ ' AND A.FDeleted = 0'
+ ' AND A.FState = 1 '--ת<EFBFBD><EFBFBD>'
+ ' AND (@FromMemNo = '''' OR A.FMemNo BETWEEN @FromMemNo AND @ToMemNo)'
+ ' AND (@MemName = '''' OR A.FName LIKE ''%'' + @MemName + ''%'')'
+ ' AND (@MobilePhone = '''' OR A.FMobilePhone = @MobilePhone)'
+ ' AND (@Gender = -1 OR A.FGender = @Gender)'
+ ' AND (@ToPoint = 0 OR A.FPoint BETWEEN @FromPoint + 0.001 AND @ToPoint)'
+ ' AND (@FromBirthday = '''' OR A.FShortBirthday BETWEEN @FromBirthday AND @ToBirthday)'
+ ' AND (@FromJoinDate IS NULL OR A.FCreateDate BETWEEN @FromJoinDate AND @ToJoinDate)'
+ ' AND (@IsVisitor IS NULL OR A.FIsVisitor = @IsVisitor)'
-- + ' AND (@BizEmpId = 0 OR A.FChargeEmpId = @BizEmpId)'
SELECT @InsertCard = 'INSERT #MemberCard(FCompId,FCardKind,FCardId,FCardNo,FMemId,FMemNo,FCardTypeId,FCardTypeNo,FCardTypeName,FState,FPurAmount,FRemainTimes,FCardMemo,FCreateDate,FExpiredDate,FBizEmpId)'
+ ' SELECT A.FCompId,''Money'',A.FCardId AS FCardId,A.FCardNo AS FCardNo,A.FMemId,'''' AS FMemNo,A.FTypeID,'''' AS FCardTypeNo,'''' AS FCardTypeName,A.FState,0 AS FPurAmount, A.FRemainTimes,A.FMemo AS FCardMemo,'
+ ' CONVERT(varchar(10), A.FCreateDate,23) AS FCreateDate,'
+ ' CONVERT(varchar(10), A.FExpiredDate,23) AS FExpiredDate, '
+ ' A.FBizEmpId'
+ ' FROM TMemberCard AS A WITH(NOLOCK)'
SELECT @InsertCourse = 'INSERT #MemberCard(FCompId,FCardKind,FCardId,FCardNo,FMemId,FMemNo,FCardTypeId,FCardTypeNo,FCardTypeName,FState,FPurAmount,FRemainTimes,FRemainPurAmount,FRemainFreeAmount,FCardMemo,FCreateDate,FExpiredDate,FItemId,FCalcMode,FBizEmpid)'
+ ' SELECT A.FCompId,''Course'',A.FId AS FCardId,'''' AS FCardNo,A.FMemId,'''' AS FMemNo,FCourseId,'''' AS FCardTypeNo,'''' AS FCardTypeName,A.FState,A.FPurAmount, A.FRemainPurTimes + A.FRemainFreeTimes,A.FRemainPurAmount,A.FRemainFreeAmount, A.FMemo ,'
+ ' CONVERT(varchar(10), A.FPurchaseDate,23) AS FCreateDate,'
+ ' CONVERT(varchar(10), A.FExpiredDate,23) AS FExpiredDate, '
+ ' A.FItemId,'
+ ' A.FCalcMode,A.FBizEmpId'
+ ' FROM TMemberCourse AS A WITH(NOLOCK)'
SELECT @CardWhere = 'WHERE 1=1
AND (@CardTypeNo = '''' OR A.FTypeId IN(SELECT FCardTypeId FROM #CardTypeIds))
AND (@FromCardNo = '''' OR A.FCardNo BETWEEN @FromCardNo AND @ToCardNo)
AND (@CardState = 0 OR A.FState = @CardState)
AND (@FromCardCreateDate IS NULL OR A.FCreateDate BETWEEN @FromCardCreateDate AND @ToCardCreateDate)
AND (@FromCardExpiredDate IS NULL OR A.FExpiredDate BETWEEN @FromCardExpiredDate AND @ToCardExpiredDate)
AND (@CardState = 0 OR A.FState = @CardState)
AND (@CardExpired = 0 OR (@CardExpired = 1 AND A.FExpiredDate > @Today /*δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/) OR (@CardExpired = -1 AND A.FExpiredDate <= @Today /*<EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/))
AND A.FDeleted = 0 /*û<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>*/
AND (@BizEmpId = 0 OR A.FBizEmpId = @BizEmpId)'
SELECT @CourseWhere = 'WHERE 1=1
AND (@CourseNo = '''' OR A.FCourseId IN(SELECT FCourseId FROM #CourseIds))
AND (@CardState = 0 OR A.FState = @CardState)
AND (@FromCardCreateDate IS NULL OR A.FPurchaseDate BETWEEN @FromCardCreateDate AND @ToCardCreateDate)
AND (@FromRemainTimes = 0 OR ((A.FRemainPurTimes + A.FRemainFreeTimes) >= @FromRemainTimes AND (A.FRemainPurTimes + A.FRemainFreeTimes) <= @ToRemainTimes))
AND (@FromCardExpiredDate IS NULL OR A.FExpiredDate BETWEEN @FromCardExpiredDate AND @ToCardExpiredDate)
AND (@CardExpired = 0 OR (@CardExpired = 1 AND (A.FExpiredDate IS NULL OR A.FExpiredDate > @Today) /*δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/) OR (@CardExpired = -1 AND A.FExpiredDate <= @Today /*<EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/))
AND (@ToCardPurAmount = 0 OR (A.FPurAmount >= @FromCardPurAmount AND A.FPurAmount <= @ToCardPurAmount))
AND (@BizEmpId = 0 OR A.FBizEmpId = @BizEmpId)'
SELECT @MemParam = N'@MemName VARCHAR(30) ,'
+ ' @MobilePhone VARCHAR(30),'
+ ' @FromMemNo VARCHAR(30),'
+ ' @ToMemNo VARCHAR(30),'
+ ' @FromPoint INT,'
+ ' @ToPoint INT,'
+ ' @FromJoinDate DATETIME,'
+ ' @ToJoinDate DATETIME,'
+ ' @Gender INT, '
+ ' @IsVisitor INT, '
+ ' @BizEmpId BIGINT, '
+ ' @FromBirthday VARCHAR(10),'
+ ' @ToBirthday VARCHAR(10)'
SELECT @CardParam = N'@CardTypeNo VARCHAR(30) ,'
+ ' @FromCardNo VARCHAR(30),'
+ ' @ToCardNo VARCHAR(30),'
+ ' @CardState INT,'
+ ' @FromCardCreateDate DATETIME,'
+ ' @ToCardCreateDate DATETIME,'
+ ' @FromCardExpiredDate DATETIME,'
+ ' @ToCardExpiredDate DATETIME,'
+ ' @BizEmpId bigint,'
+ ' @CardExpired INT, '
+ ' @FromCardPurAmount DECIMAL(18,6), '
+ ' @ToCardPurAmount DECIMAL(18,6), '
+ ' @Today VARCHAR(10) '
SELECT @CourseParam = N'@CourseNo VARCHAR(30) ,'
+ ' @CardState INT,'
+ ' @FromCardCreateDate DATETIME,'
+ ' @ToCardCreateDate DATETIME,'
+ ' @FromCardExpiredDate DATETIME,'
+ ' @ToCardExpiredDate DATETIME,'
+ ' @CardExpired INT, '
+ ' @FromCardPurAmount DECIMAL(18,6), '
+ ' @ToCardPurAmount DECIMAL(18,6), '
+ ' @FromRemainTimes INT, '
+ ' @ToRemainTimes INT, '
+ ' @BizEmpId bigint,'
+ ' @Today VARCHAR(10) '
DECLARE @Sql NVARCHAR(4000)
IF @CompSource = 2 --<EFBFBD>Կ<EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾Ϊ׼, <EFBFBD><EFBFBD>ͳ<EFBFBD>ƿ<EFBFBD>
BEGIN
IF @ShowCardInfo = 1
BEGIN
SELECT @Sql = @InsertCard + ' INNER JOIN #MemCompIds AS C ON C.FCompId = A.FCompId ' + @CardWhere
-- PRINT @Sql
exec sp_executesql @sql,@CardParam,
@CardTypeNo = @CardTypeNo,
@FromCardNo = @FromCardNo,
@ToCardNo = @ToCardNo,
@CardState = @CardState,
@ToCardCreateDate = @ToCardCreateDate,
@FromCardExpiredDate = @FromCardExpiredDate,
@ToCardExpiredDate = @ToCardExpiredDate,
@FromCardCreateDate = @FromCardCreateDate,
@FromCardPurAmount = @FromCardPurAmount,
@ToCardPurAmount = @ToCardPurAmount,
@CardExpired = @CardExpired,
@Today = @Today,
@BizEmpId = @BizEmpId
END
IF @ShowCourseInfo = 1
BEGIN
SELECT @Sql = @InsertCourse + ' INNER JOIN #MemCompIds AS C ON C.FCompId = A.FCompId ' + @CourseWhere
PRINT @Sql
exec sp_executesql @sql,@CourseParam,
@CourseNo = @CourseNo,
@CardState = @CardState,
@ToCardCreateDate = @ToCardCreateDate,
@FromRemainTimes = @FromRemainTimes,
@ToRemainTimes = @ToRemainTimes,
@FromCardCreateDate = @FromCardCreateDate,
@FromCardExpiredDate = @FromCardExpiredDate,
@ToCardExpiredDate = @ToCardExpiredDate,
@CardExpired = @CardExpired,
@FromCardPurAmount = @FromCardPurAmount,
@ToCardPurAmount = @ToCardPurAmount,
@Today = @Today,
@BizEmpId = @BizEmpId
END
--EXEC (@Sql)
SELECT @Sql = @InsertMember + @MemberWhere + ' AND (EXISTS(SELECT 1 FROM TMemberCard AS B,#MemCompIds AS C WHERE B.FMemId = A.FMemId AND B.FDeleted=0 AND B.FCompId = C.FCompId)
OR EXISTS(SELECT 1 FROM TMemberCourse AS B,#MemCompIds AS C WHERE B.FMemId = A.FMemId AND B.FCompId = C.FCompId) OR (FIsVisitor = 1 AND EXISTS(SELECT 1 FROM #MemCompIds AS D WHERE D.FCompId = A.FCompId)) )'
PRINT @Sql
print @MemParam
exec sp_executesql @sql,@MemParam,
@MemName = @MemName,
@FromMemNo = @FromMemNo,
@ToMemNo = @ToMemNo,
@Gender = @Gender,
@IsVisitor = @IsVisitor,
@FromJoinDate = @FromJoinDate,
@ToJoinDate = @ToJoinDate,
@FromPoint = @FromPoint,
@ToPoint = @ToPoint,
@BizEmpId = @BizEmpId,
@MobilePhone = @MobilePhone,
@FromBirthday = @FromBirthday,
@ToBirthday = @ToBirthday
END
ELSE
BEGIN
SELECT @Sql = @InsertMember + ' INNER JOIN #MemCompIds AS C ON C.FCompId = A.FCompId ' + @MemberWhere
PRINT @Sql
print @MemParam
exec sp_executesql @sql,@MemParam,
@MemName = @MemName,
@FromMemNo = @FromMemNo,
@ToMemNo = @ToMemNo,
@Gender = @Gender,
@IsVisitor = @IsVisitor,
@FromJoinDate = @FromJoinDate,
@ToJoinDate = @ToJoinDate,
@FromPoint = @FromPoint,
@ToPoint = @ToPoint,
@BizEmpId = @BizEmpId,
@MobilePhone = @MobilePhone,
@FromBirthday = @FromBirthday,
@ToBirthday = @ToBirthday
IF @ShowCardInfo = 1
BEGIN
IF @ShowCourseInfo = 0
BEGIN
SELECT @Sql = @InsertCard + @CardWhere + ' AND EXISTS(SELECT 1 FROM #MemCompIds AS C WHERE C.FCompId = A.FCompId) '
END
ELSE
BEGIN
SELECT @Sql = @InsertCard + @CardWhere + ' AND EXISTS(SELECT 1 FROM #Member AS C WHERE C.FMemId = A.FMemId) '
END
PRINT @Sql
exec sp_executesql @sql,@CardParam,
@CardTypeNo = @CardTypeNo,
@FromCardNo = @FromCardNo,
@ToCardNo = @ToCardNo,
@CardState = @CardState,
@ToCardCreateDate = @ToCardCreateDate,
@FromCardCreateDate = @FromCardCreateDate,
@FromCardExpiredDate = @FromCardExpiredDate,
@ToCardExpiredDate = @ToCardExpiredDate,
@CardExpired = @CardExpired,
@FromCardPurAmount = @FromCardPurAmount,
@ToCardPurAmount = @ToCardPurAmount,
@Today = @Today,
@BizEmpId = @BizEmpId
END
IF @ShowCourseInfo = 1
BEGIN
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾
IF @ShowCourseInfo = 0
BEGIN
SELECT @Sql = @InsertCourse + @CourseWhere + ' AND EXISTS(SELECT 1 FROM #MemCompIds AS C WHERE C.FCompId = A.FCompId) '
END
ELSE
BEGIN
SELECT @Sql = @InsertCourse + @CourseWhere + ' AND EXISTS(SELECT 1 FROM #Member AS C WHERE C.FMemId = A.FMemId) '
END
PRINT @Sql
exec sp_executesql @sql,@CourseParam,
@CourseNo = @CourseNo,
@CardState = @CardState,
@ToCardCreateDate = @ToCardCreateDate,
@FromRemainTimes = @FromRemainTimes,
@ToRemainTimes = @ToRemainTimes,
@FromCardCreateDate = @FromCardCreateDate,
@FromCardExpiredDate = @FromCardExpiredDate,
@ToCardExpiredDate = @ToCardExpiredDate,
@CardExpired = @CardExpired,
@FromCardPurAmount = @FromCardPurAmount,
@ToCardPurAmount = @ToCardPurAmount,
@Today = @Today,
@BizEmpId = @BizEmpId
END
END
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>
--ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
DELETE A
FROM #MemberCard AS A
WHERE NOT EXISTS(SELECT 1 FROM #Member AS B WHERE A.FMemId = B.FMemId)
IF @ShowAllMember != 1
BEGIN
DELETE A
FROM #Member AS A
WHERE NOT EXISTS(SELECT 1 FROM #MemberCard AS B WHERE A.FMemId = B.FMemId)
END
IF @ShowCourseInfo = 1
BEGIN
INSERT #MemberCardAccount(FMemId,FCardId,FAcctId,FBalance,FArrear)
SELECT A.FMemId,A.FCardId,6,A.FRemainPurAmount + A.FRemainFreeAmount,0
-- INTO #MemberCardAccount
FROM #MemberCard AS A
WHERE A.FCardKind = 'Course'
END
--ɢ<EFBFBD><EFBFBD>
UPDATE #Member
SET FName = FName + '<EFBFBD><EFBFBD>]'
WHERE FIsVisitor = 1
--ͳ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>
UPDATE A
SET A.FArrear = B.FArrear
FROM #Member AS A,(
SELECT A.FMemId ,SUM(FRemainArrear) AS FArrear
FROM TMemberArrear AS A,#Member AS M
WHERE M.FMemId = A.FMemId
GROUP BY A.FMemId) AS B
WHERE A.FMemID = B.FMemId
IF @FromArrear > 0
BEGIN
DELETE #Member WHERE FArrear < @FromArrear OR FArrear > @ToArrear
DELETE A
FROM #MemberCard AS A
WHERE NOT EXISTS(SELECT 1 FROM #Member AS B WHERE A.FMemId = B.FMemId)
END
IF @ShowCardInfo = 1 --AND @BalanceCutDate != ''
BEGIN
INSERT #MemberCardAccount(FMemId,FCardId,FAcctId,FBalance,FArrear)
SELECT A.FMemId,A.FCardId,A.FAcctId,A.FBalance,A.FArrear
-- INTO #MemberCardAccount
FROM TMemberCardAccount AS A,#MemberCard AS B
WHERE A.FCardId = B.FCardId
AND B.FCardKind = 'Money'
AND ( @FromAcctExpiredDate IS NULL OR (A.FExpiredDate IS NOT NULL AND A.FExpiredDate BETWEEN @FromAcctExpiredDate AND @ToAcctExpiredDate))
IF @FromAcctExpiredDate IS NOT NULL
BEGIN
DELETE A
FROM #MemberCard AS A
WHERE NOT EXISTS(SELECT 1 FROM #MemberCardAccount AS B WHERE A.FCardId = B.FCardId)
DELETE A
FROM #Member AS A
WHERE NOT EXISTS(SELECT 1 FROM #MemberCard AS B WHERE A.FMemId = B.FMemId)
END
IF @BalanceCutDate != ''
BEGIN
--<EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FBalance = 0
FROM #MemberCardAccount AS A,#MemberCard AS B
WHERE A.FCardId = B.FCardId
AND B.FCardKind = 'Money'
-- AND B.FCreateDate > @BalanceCutDate + ' 23:59:59'
UPDATE A
SET A.FBalance = B.FBalance
FROM #MemberCardAccount AS A,TMemberCardAcctHist AS B,
(
SELECT FCardId,FAcctId,MAX(FTime) AS FTime
FROM TMemberCardAcctHist AS H
WHERE FTime <= @BalanceCutDate + ' 23:59:59'
GROUP BY FCardId,FAcctId
) AS C
WHERE A.FCardId = B.FCardId
AND A.FAcctId = B.FAcctId
AND B.FCardId = C.FCardId
AND B.FAcctId = C.FAcctId
AND B.FTime = C.FTime
END
--ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF @AcctNo != '' --AND @FromBalance != 0 AND @ToBalance != 0
BEGIN
DECLARE @AcctId BIGINT
SELECT @AcctId = FId FROM TPayAccount WITH(NOLOCK) WHERE FNo = @AcctNo
IF @AcctId != 0
BEGIN
DELETE A
FROM #MemberCard AS A,#MemberCardAccount AS B
WHERE A.FCardId = B.FCardId
AND B.FAcctId = @AcctId
AND B.FBalance NOT BETWEEN @FromBalance AND @ToBalance
DELETE A
FROM #MemberCard AS A
WHERE NOT EXISTS(SELECT TOP 1 1 FROM #MemberCardAccount AS B WITH(NOLOCK) WHERE A.FCardId = B.FCardId AND B.FAcctId = @AcctId)
END
END
END
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD>Ͱѻ<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF @CompanyForCard = 1 OR @CardTypeNo != '' OR @FromCardNo != '' OR @CardState != 0 OR @FromCardCreateDate != '' OR @FromCardExpiredDate != '' OR @AcctNo != ''
BEGIN
DELETE A
FROM #Member AS A
WHERE NOT EXISTS(SELECT 1 FROM #MemberCard AS B WHERE A.FMemId = B.FMemId)
AND FIsVisitor = 0
END
--select @CardTypeNo,@FromCardNo,@ToCardNo,@CardState,@FromCardCreateDate,@FromCardExpiredDate
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FLastDate = CONVERT(varchar(10), B.Date,23)
FROM #Member AS A,
(
SELECT A.FMemId,MAX(FTime) AS Date
FROM TMemberTransHist AS A WITH(NOLOCK),#Member AS B
WHERE A.FMemId = B.FMemId
GROUP BY A.FMemId
) AS B
WHERE A.FMemid = B.FMemId
--IF EXISTS(SELECT TOP 1 1 FROM TMemberOldTransHist WITH(NOLOCK))
--BEGIN
-- --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- UPDATE A
-- SET A.FLastDate = CONVERT(varchar(10), B.Date,23)
-- FROM #Member AS A,
-- (
-- SELECT A.FMemId,MAX(FTime) AS Date
-- FROM TMemberOldTransHist AS A WITH(NOLOCK),#Member AS B
-- WHERE A.FMemId = B.FMemId
-- AND B.FLastDate = ''
-- GROUP BY A.FMemId
-- ) AS B
-- WHERE A.FMemid = B.FMemId
--END
IF @FromLastDate != ''
BEGIN
--<EFBFBD>ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DELETE #Member
WITH(ROWLOCK)
WHERE FLastDate NOT BETWEEN @FromLastDate AND @ToLastDate
END
IF @NotComeDay != 0
BEGIN
DECLARE @NoComeDate VARCHAR(10)
SELECT @NoComeDate = CONVERT(VARCHAR(10) ,(SELECT DATEADD(d,-@NotComeDay,getdate())),23)
DELETE #Member WITH(ROWLOCK)
WHERE FLastDate > @NoComeDate
END
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF @AfterLastDate != ''
BEGIN
DELETE #Member
WHERE FLastDate > @AfterLastDate
END
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FConsTimes = B.Times
FROM #Member AS A,
(
SELECT FMemId,SUM(1) AS Times
FROM (
SELECT FMemId,SUM(1) AS Times
FROM TMemberTransHist WITH(NOLOCK)
WHERE FBillType = 'XF'
AND (@FromStatDate = '' OR FTime BETWEEN @FromStatDate AND @ToStatDate)
GROUP BY FMemId,FTransId) AS C
GROUP BY FMemId
) AS B
WHERE A.FMemId = B.FMemId
--IF EXISTS(SELECT TOP 1 1 FROM TMemberOldTransHist WITH(NOLOCK))
--BEGIN
-- UPDATE A
-- SET A.FConsTimes = ISNULL(A.FConsTimes,0) + B.Times
-- FROM #Member AS A,
-- (
-- SELECT FMemId,SUM(1) AS Times
-- FROM TMemberOldTransHist WITH(NOLOCK)
-- WHERE FBillType = 'DR.XF'
-- AND (@FromStatDate = '' OR FTime BETWEEN @FromStatDate AND @ToStatDate)
-- GROUP BY FMemId,FTransNo
-- ) AS B
-- WHERE A.FMemId = B.FMemId
--END
--<EFBFBD>ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>
IF @FromConsTimes IS NOT NULL
BEGIN
DELETE #Member WITH(ROWLOCK)
WHERE FConsTimes NOT BETWEEN @FromConsTimes AND @ToConsTimes
END
IF db_name() = 'JiNan_JinZhi'
BEGIN
--<EFBFBD><EFBFBD><EFBFBD>Ѻͳ<EFBFBD>ֵ<EFBFBD>ܽ<EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FConsAmt = B.ConsAmt,
A.FRchgAmt = B.RchgAmt
FROM #Member AS A,
(
SELECT FMemId,SUM(ConsAmt) AS ConsAmt,SUM(RchgAmt) AS RchgAmt
FROM (SELECT A.FMemId,SUM(CASE WHEN FBillType = 'XF' THEN FAmount ELSE 0 END) AS ConsAmt,
SUM(CASE WHEN FBizType IN('CourseSale_<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','CardRchg','CardSale','CoursePackSale_<EFBFBD><EFBFBD><EFBFBD><EFBFBD>') THEN FAmount ELSE 0 END) AS RchgAmt
FROM TMemberTransHist AS A WITH(NOLOCK),#Member AS C
WHERE A.FMemId = C.FMemId
AND FBillType IN('XF','KK')
AND (@FromStatDate = '' OR FTime BETWEEN @FromStatDate AND @ToStatDate)
AND EXISTS(SELECT 1 FROM #MemberCard AS B WHERE B.FCardId = A.FCardId)
GROUP BY A.FMemId,FBillType,FBizType) AS T
GROUP BY FMemId
) AS B
WHERE A.FMemId = B.FMemId
END
ELSE
BEGIN
--<EFBFBD><EFBFBD><EFBFBD>Ѻͳ<EFBFBD>ֵ<EFBFBD>ܽ<EFBFBD><EFBFBD><EFBFBD>
DECLARE @BizType_CourseSale VARCHAR(100)
DECLARE @BizType_CoursePackSale VARCHAR(100)
DECLARE @BizType_CardSale VARCHAR(100)
DECLARE @BizType_CardRchg VARCHAR(100)
IF @ShowCardInfo = 1
BEGIN
SELECT @BizType_CardSale = 'CardSale'
SELECT @BizType_CardRchg = 'CardRchg'
END
ELSE
BEGIN
SELECT @BizType_CardSale = 'NAN'
SELECT @BizType_CardRchg = 'NAN'
END
IF @ShowCourseInfo = 1
BEGIN
SELECT @BizType_CourseSale = 'CourseSale'
SELECT @BizType_CoursePackSale = 'CoursePackSale'
END
ELSE
BEGIN
SELECT @BizType_CourseSale = 'NAN'
SELECT @BizType_CoursePackSale = 'NAN'
END
UPDATE A
SET A.FConsAmt = B.ConsAmt,
A.FRchgAmt = B.RchgAmt
FROM #Member AS A,
(
SELECT FMemId,SUM(ConsAmt) AS ConsAmt,SUM(RchgAmt) AS RchgAmt
FROM (SELECT A.FMemId,SUM(CASE WHEN FBillType = 'XF' THEN FAmount ELSE 0 END) AS ConsAmt,
SUM(CASE WHEN FBizType IN(@BizType_CourseSale,@BizType_CardRchg,@BizType_CardSale,@BizType_CoursePackSale) THEN FAmount ELSE 0 END) AS RchgAmt
FROM TMemberTransHist AS A WITH(NOLOCK),#Member AS C
WHERE A.FMemId = C.FMemId
AND FBillType IN('XF','KK')
AND (@FromStatDate = '' OR FTime BETWEEN @FromStatDate AND @ToStatDate)
GROUP BY A.FMemId,FBillType,FBizType) AS T
GROUP BY FMemId
) AS B
WHERE A.FMemId = B.FMemId
END
--<EFBFBD>ܴ<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF @ShowCardConsAmt = 1
BEGIN
UPDATE A
SET A.FCardConsAmt = B.FConsAmt
FROM #Member AS A,(
SELECT A.FMemId,SUM(A.FOutAmount) AS FConsAmt
FROM TMemberCardAcctHist AS A ,#Member AS B
WHERE B.FMemId = A.FMemId
AND (@FromStatDate = '' OR FTime BETWEEN @FromStatDate AND @ToStatDate)
AND A.FBizType = 'XF'
GROUP BY A.FMemId) AS B
WHERE A.FMemId = B.FMemId
IF EXISTS(SELECT 1 FROM TMemberCardOldAcctHist)
BEGIN
UPDATE A
SET A.FCardConsAmt = ISNULL(A.FCardConsAmt,0) + B.FConsAmt
FROM #Member AS A,(
SELECT A.FMemId,SUM(A.FOutAmount) AS FConsAmt
FROM TMemberCardOldAcctHist AS A ,#Member AS B
WHERE B.FMemId = A.FMemId
AND A.FBizType = '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
AND (@FromStatDate = '' OR FTime BETWEEN @FromStatDate AND @ToStatDate)
GROUP BY A.FMemId) AS B
WHERE A.FMemId = B.FMemId
END
--<EFBFBD><EFBFBD><EFBFBD>޿<EFBFBD>ҲҪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ
UPDATE A
SET A.FCardConsAmt = A.FCardConsAmt + B.FConsAmt
FROM #Member AS A,(
SELECT A.FMemId,SUM(B.FPayAmt)AS FConsAmt
FROM TMemberTransHistPayment AS B,TMemberTransHist AS A,#Member AS M
WHERE A.FMemId = B.FMemId
AND M.FMemId = B.FMemId
AND A.FBillType = B.FBillType
AND A.FTransId = B.FTransId
AND A.FTransDetailId = B.FTransDetailId
AND B.FPayTypeId = 7
AND A.FBillType = 'XF'
AND (@FromStatDate = '' OR FTime BETWEEN @FromStatDate AND @ToStatDate)
GROUP BY A.FMemId
) AS B
WHERE A.FMemId = B.FMemId
END
--IF EXISTS(SELECT TOP 1 1 FROM TMemberOldTransHist WITH(NOLOCK))
--BEGIN
-- --<EFBFBD><EFBFBD><EFBFBD>Ѻͳ<EFBFBD>ֵ<EFBFBD>ܽ<EFBFBD><EFBFBD><EFBFBD>
-- UPDATE A
-- SET A.FConsAmt = ISNULL(A.FConsAmt,0) + B.ConsAmt,
-- A.FRchgAmt = ISNULL(A.FRchgAmt,0) + B.RchgAmt
-- FROM #Member AS A,
-- (
-- SELECT FMemId,SUM(ConsAmt) AS ConsAmt,SUM(RchgAmt) AS RchgAmt
-- FROM (SELECT A.FMemId,SUM(CASE WHEN FBillType = 'DR.XF' THEN FAmount ELSE 0 END) AS ConsAmt,
-- SUM(CASE WHEN FBizType IN('DR.CardSale','DR.CardRchg') THEN FAmount ELSE 0 END) AS RchgAmt
-- FROM TMemberOldTransHist AS A WITH(NOLOCK),#Member AS C
-- WHERE A.FMemId = C.FMemId
-- AND FBillType IN('DR.XF','DR.KK')
-- AND (@FromStatDate = '' OR FTime BETWEEN @FromStatDate AND @ToStatDate)
-- GROUP BY A.FMemId,FBillType) AS T
-- GROUP BY FMemId
-- ) AS B
-- WHERE A.FMemId = B.FMemId
--END
--<EFBFBD>ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѳ<EFBFBD>ֵ<EFBFBD>ܶ<EFBFBD>
IF (@FromConsAmt IS NOT NULL AND @ToConsAmt IS NOT NULL)
BEGIN
DELETE #Member
WHERE FConsAmt NOT BETWEEN @FromConsAmt AND @ToConsAmt
END
IF (@FromRchgAmt IS NOT NULL AND @ToRchgAmt IS NOT NULL)
BEGIN
IF @FromRchgAmt = 0
BEGIN
SET @FromRchgAmt = 0.001
END
DELETE #Member
WHERE FRchgAmt NOT BETWEEN @FromRchgAmt AND @ToRchgAmt
END
--<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>
UPDATE A
SET A.FFavoriteEmpName = CASE WHEN A.FFavoriteEmpName IS NULL THEN E.FName ELSE A.FFavoriteEmpName END
FROM #Member AS A,
(
SELECT TOP 1000000000 A.FMemId,C.FEmpId,SUM(1) AS SUM
FROM #Member AS A,TConsumeBill AS T WITH(NOLOCK),TConsumeItemEmployee AS C WITH(NOLOCK)
WHERE A.FMemId = T.FMemId
AND T.FBillId = C.FBillId
AND C.FEmpId != 0
AND C.FDispatchMode = 10001
AND T.FState = 1
GROUP BY A.FMemId,C.FEmpId
ORDER BY A.FMemId,SUM(1) DESC
)AS B ,TEmployee AS E
WHERE A.FMemId = B.FMemId
AND B.FEmpId = E.FId
AND (@FavoriteEmpId = 0 OR B.FEmpId = @FavoriteEmpId)
--<EFBFBD>ų<EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>
IF @FavoriteEmpId != 0
BEGIN
DELETE #Member WHERE FFavoriteEmpName = '' OR FFavoriteEmpName IS NULL
END
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ο<EFBFBD>
DELETE A
FROM #MemberCard AS A
WHERE NOT EXISTS(SELECT 1 FROM #Member AS B WHERE A.FMemId = B.FMemId)
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FCardTypeName = B.FNo + '-' + B.FName
FROM #MemberCard AS A,TMemberCardType AS B
WHERE A.FCardTypeId = B.FId
AND A.FCardKind = 'Money'
--<EFBFBD>Ƴ<EFBFBD>
UPDATE A
SET A.FCardTypeName = B.FNo + '-' + B.FName
FROM #MemberCard AS A,TCourse AS B
WHERE A.FCardTypeId = B.FId
AND A.FCardKind = 'Course'
AND B.FName != ''
--<EFBFBD><EFBFBD>Ŀ
UPDATE A
SET A.FCardTypeName = B.FNo + '-' + B.FName
FROM #MemberCard AS A,TItem AS B
WHERE A.FItemId = B.FId
AND A.FCardKind = 'Course'
AND A.FCardTypeName IN('-','')
AND A.FCardTypeName = ''
--<EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD>
UPDATE #Member SET FConsPrice = FConsAmt / FConsTimes
WHERE FConsTimes > 0
--<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>
/* UPDATE A
SET A.FSaleEmpName = E.FName
FROM #Member AS A,TEmployee AS E WITH(NOLOCK)
WHERE E.FId = A.FChargeEmpId
*/
UPDATE A
SET A.FBizEmpName = E.FName
FROM #MemberCard AS A,TEmployee AS E WITH(NOLOCK)
WHERE E.FId = A.FBizEmpId
SELECT FMemId AS MemId, FMemNo AS MemNo, A.FName AS Name, A.FMemMemo AS MemMemo, ISNULL(C.FAbbr,'') AS MemCompName, FGender AS Gender, FMobilePhone AS MobilePhone,
FBirthday AS Birthday, FBirthdayType AS BirthdayType,FJoinDate AS JoinDate, FPoint AS Point, FArrear AS Arrear,
FConsTimes AS ConsTimes,FCardConsAmt AS CardConsAmt, FConsAmt AS ConsAmt, FRchgAmt AS RchgAmt, FLastDate AS LastDate,
FConsArrear AS ConsArrear, FCourseArrear AS CourseArrear,FConsPrice AS ConsPrice,
FFavoriteEmpName AS FavoriteEmpName,FSaleEmpName AS SaleEmpName
FROM #Member AS A
LEFT JOIN TCompany AS C WITH(NOLOCK) ON A.FCompId = C.FId
ORDER BY FMemNo
SELECT A.FMemId AS MemId,A.FCardId AS CardId,A.FCardNo AS CardNo, B.FMemNo AS MemNo, A.FCardMemo AS CardMemo,ISNULL(C.FAbbr,'') AS CardCompName, A.FCardTypeNo AS CardTypeNo,A.FCardTypeName AS CardTypeName,
A.FCreateDate AS CardCreateDate,A.FExpiredDate AS CardExpiredDate,CASE WHEN A.FCalcMode = 2 THEN '<EFBFBD><EFBFBD><EFBFBD>޴<EFBFBD>' ELSE CAST(CAST( A.FRemainTimes AS FLOAT) AS VARCHAR(20)) END AS CardRemainTimes,
A.FPurAmount AS CardPurAmount, A.FState AS CardState,A.FBizEmpName AS BizEmpName
FROM #MemberCard AS A
INNER JOIN #Member AS B ON A.FMemId = B.FMemId
LEFT JOIN TCompany AS C WITH(NOLOCK) ON A.FCompId = C.FId
ORDER BY FCardNo
--<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- IF @ShowCardInfo = 1
-- BEGIN
DECLARE @CourseName VARCHAR(30)
EXEC PGetBizParameter 1,'CourseDefineName',@CourseName output
SELECT @CourseName = @CourseName + '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
SELECT B.FCardId AS CardId, B.FCardNo AS CardNo,I.FNo AS AcctNo,CASE A.FAcctId WHEN 6 THEN @CourseName ELSE I.FName END AS AcctName ,A.FBalance AS Balance,A.FArrear AS Arrear
FROM #MemberCardAccount AS A WITH(NOLOCK),#MemberCard AS B,TPayAccount AS I ,#Member AS M
WHERE A.FCardId = B.FCardId
AND A.FAcctId = I.FId
AND M.FMemId = B.FMemId
-- AND B.FCardKind = 'Money'
ORDER BY B.FCardNo
CREATE TABLE #TransHist
(
FPayTypeId BIGINT,
FPayTypeNo VARCHAR(100),
FPayTypeName VARCHAR(100),
FPayAmt DECIMAL(18,6)
)
--SELECT * INTO ##Member FROM #Member
INSERT #TransHist(FPayTypeId,FPayTypeNo,FPayTypeName,FPayAmt)
SELECT A.FPayTypeId,P.FNo,P.FName,SUM(A.FPayAmt)
FROM TMemberTransHistPayment AS A
INNER JOIN TMemberTransHist AS B ON B.FMemId = A.FMemId AND A.FTransId = B.FTransId AND A.FTransDetailId = B.FTransDetailId AND A.FBillType = B.FBillType
LEFT JOIN TPayAccount AS P ON P.FId = A.FPayTypeId
WHERE A.FMemId IN(SELECT FMemId FROM #Member)
AND A.FBillType = 'XF'
GROUP BY A.FPayTypeId,P.FName,P.FNo
SELECT FPayTypeName as ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,FPayAmt AS <EFBFBD><EFBFBD><EFBFBD><EFBFBD> FROM #TransHist ORDER BY FPayTypeNo
select sum(FAmount)
FROM TMemberTransHist
WHERE FMemId IN(SELECT FMemId FROM #Member)
AND FBillType = 'XF'
select sum(FPayAmt)
FROM TMemberTransHistPayment
WHERE FMemId IN(SELECT FMemId FROM #Member)
AND FBillType = 'XF'
select sum(FAmount)
FROM TMemberTransHist
WHERE FMemId IN(SELECT FMemId FROM #Member)
AND FBillType = 'KK'
AND FBizType IN('CourseSale','CoursePackSale')
/* SELECT A.* INTO ##TransHist
FROM TMemberTransHist AS A
WHERE A.FMemId IN(SELECT FMemId FROM #Member)
AND A.FBillType = 'XF'
AND A.FTransId IN(SELECT FTransId FROM TMemberTransHistPayment WHERE FPayTypeId != 3 AND FPayAmt != 0)
*/
/*
SELECT * FROM TMemberTransHist WHERE FTransDetailId NOT IN(SELECT FTransDetailId FROM TMemberTransHistPayment)
AND FBillType = 'XF'
INSERT TMemberTransHistPayment(FMemId,FCardId,FBillType,FTransId,FTransDetailId,FPayTypeId,FPayAmt)
SELECT A.FMemId,B.FCardId,'XF',A.FTransid,B.FDetailId,FPayTypeId,FPayAmt
FROM TCOnsumeGoodsPayment AS B,TMemberTransHist AS A
WHERE A.FTransid = B.FBillId
AND A.FTransDetailId = B.FDetailId
AND A.FTransDetailId NOT IN(SELECT FTransDetailId FROM TMemberTransHistPayment)
SELECT count(*) FROM TMemberTransHist AS A,
(SELECT FMemId,FTransId,FTransDetailId,SUM(FPayAmt)FPayAmt FROM TMemberTransHistPayment GROUP BY FMemId,FTransId,FTransDetailId) AS B
WHERE A.FTransId = B.FTransId
AND A.FMemId = B.FMemId
AND A.FTransDetailId = B.FTransDetailId
AND A.FBillType = 'XF'
AND A.FMemId IN(SELECT FMemId FROM ##Member)
SELECT COUNT(1) FROM TMemberTransHist WHERE FMemId IN(SELECT FMemId FROM ##Member)
SELECT COUNT(1) FROM TMemberTransHist WHERE FMemId IN(SELECT FMemId FROM ##Member)
*/
/* UPDATE A
SET A.FMemId = B.FMemId
FROM TMemberTransHistPayment AS A, TMemberTransHist AS B
WHERE A.FTransId = B.FTransiD
AND A.FTransDetailId = B.FTransDetailId
AND A.FMemId != B.FMemId
*/
-- SELECT * FROM TConsumeBill
-- WHERE FBillId NOT IN(SELECT FTransId FROM TMemberTransHistPayment)
-- AND FMemId != 0
/*
select * from ggm01 where gga00c = '005' order by gga02d desc
select * from TMemberTransHist WHERE FTransId NOT IN(SELECT FTransid FROM TMemberTransHistPayment)
AND FBillType = 'XF'
SELECT A.FTransId,A.FAmount, B.FPayAmt
FROM TMemberTransHist AS A,(SELECT FTransid,FTransDetailId,FBillType,SUM(FPayAmt) AS FPayAmt FROM TMemberTransHistPayment GROUP BY FTransDetailId,FTransId,FBillType) AS B
WHERE A.FTransId = B.FTransId
AND A.FBillType= B.FBillType
AND A.FTransDetailId = B.FTransDetailId
AND A.FAmount != B.FPayAmt
SELECT * FROM TMemberTransHist WHERE FTransId = 5629196643205643967
SELECT * FROM TMemberTransHistPayment WHERE FTransId = 5629196643205643967
SELECT * FROM TConsumeItemPayment WHERE FBillId = 5629196643205643967
SELECT * FROM TConsumeItem WHERE FBillId = 5629196643205643967
UPDATE A
SET A.FAmount = B.FPayAmt
FROM TConsumeItem AS A, (SELECT FBillId,FDetailId ,SUM(FPayAmt) AS FPayAmt FROM TConsumeItemPayment GROUP BY FBillId,FDetailId ) AS B
WHERE A.FBillId = B.FBillId
AND A.FId = B.FDetailId
AND A.FAmount != B.FPayAmt
UPDATE A
SET A.FAmount = B.FAmount
FROM TMemberTransHist AS A,TConsumeItem AS B
WHERE A.FTransDetailId = B.FId
AND A.FAmount != B.FAmount
AND A.FBIlLType = 'XF'
*/
-- SELECT * FROM TMemberTransHistPayment
-- WHERE FTransId NOT IN(SELECT )
-- EXEC PRptMemberReport 'Company="005"CompNo="005"CompSource="2"ShowCardInfo="1"CardExpired="0"ShowCourseInfo="1"ShowAllMember="1"IsVisitor="0"LoginUserNo="System"ShowCardConsAmt="0"'
-- select * from ##Member
--SELECT * FROM TConsumeBill WHERE FCompId = dbo.FNCompId('005')ORDER BY FBillTime
-- END
-- ELSE
-- BEGIN
-- SELECT '' AS CardNo ,'' AS AcctNo ,'' AS AcctName,CAST(0 AS DECIMAL(18,6)) AS Balance ,CAST(0 AS DECIMAL(18,6)) AS Arrear
--END
-- select * from TMember
--83807855
--15589888082
--SELECT * FROM TMemberTransHist
--DECLARE @IParam VARCHAR(8000)
--SELECT @IParam =
-- '
-- FromMemNo=""
-- ToMemNo="888"
-- CompanyForCard="1"
-- CardTypeNo="A"
-- Company="001,002,003,A001"
-- MobilePhone=""
-- FromBirthday=""
-- ToBirthday="1-1209"
-- FromLastDate="2012-01-01"
-- ToLastDate="2015-05-01"
-- '
--EXEC PRptMemberReport @IParam
END
go
SELECT SUM(FInAmount) , SUM(FOutAmount) FROM TMemberCardAcctHist
WHERE FMemId IN(SELECT FMemId FROM ##Member)
AND FBillType IN( 'KK')
AND FAcctId = 3
AND FCardId IN(SELECT FCardId FROM TMemberCard WHERE FState != 1)
SELECT * FROM ##Member WHERE FMemId IN(SELECT FMemId FROM TMemberCard WHERE FState != 1)
SELECT * FROM TMemberCardAcctHist WHERE FTransId NOT IN(SELECT FTransid FROM TMemberTransHist)
AND FMemId IN(SELECT FMemId FROM ##Member)
SELECT * FROM TMemberTransHist WHERE FTransId = 5240051834208077595
DROP TABLE #Acct
SELECT A.FTransId,SUM(A.FOutAmount) AS FAmt
INTO #Acct
FROM TMemberCardAcctHist AS A
WHERE FMemId IN(SELECT FMemId FROM ##Member)
AND FBillType IN( 'KK' )
AND FAcctId = 3
GROUP BY A.FTransId
drop table #Pay
SELECT P.FTransid,SUM(P.FPayAmt) AS FAmt
INTO #Pay
FROM TMemberTransHistPayment AS P
WHERE P.FMemId IN(SELECT FMemId FROM ##Member)
AND P.FPayTypeId = 3
AND P.FBillType = 'KK'
GROUP BY FTransid
SELECT * FROM #Acct AS A,#Pay AS B
WHERE A.FTransId = B.FTransId
AND A.FAmt != B.FAmt
SELECT * FROM #Pay WHERE FTransId NOT IN(SELECT FTransiD FROM #Acct)
SELECT * FROM #Acct WHERE FTransId NOT IN(SELECT FTransiD FROM #Pay)
AND FAmt > 0
SELECT * FROM TMemberCardAcctHist WHERE FTransId = 5089286496175623033
SELECT * FROM TMemberTransHistPayment WHERE FTransId = 5089286496175623033
SELECT * FROM TMemberTransHistPayment WHERE FTransId NOT IN(SELECT FTransId FROM TMemberCardAcctHist)
AND FPayTypeId = 3
AND FMemId IN(SELECT FMemId FROM ##Member)
SELECT A.FPayTypeId,P.FNo,P.FName,SUM(A.FPayAmt)
FROM TMemberTransHistPayment AS A
INNER JOIN TMemberTransHist AS B ON B.FMemId = A.FMemId AND A.FTransId = B.FTransId AND A.FTransDetailId = B.FTransDetailId AND A.FBillType = B.FBillType
LEFT JOIN TPayAccount AS P ON P.FId = A.FPayTypeId
WHERE A.FMemId IN(SELECT FMemId FROM ##Member)
AND A.FBillType = 'XF'
GROUP BY A.FPayTypeId,P.FName,P.FNo
SELECT SUM(FAmt) FROM #Pay
SELECT SUM(FAmt) FROM #Acct
SELECT SUM(FInAmount) FROM TMemberCardAcctHist WHERE FMemId IN(SELECT FMemId FROM ##Member)
AND FAcctId = 3
AND FBillType = 'KK'
SELECT * FROM TMemberCard WHERE FDeleted = 1 AND FMemId IN(SELECT FMemId FROM ##Member)
SELECT SUM(FInAmount) FROM TMemberCardAcctHist WHERE FMemId IN(SELECT FMemId FROM ##Member)
AND FBillType ='DR'
AND FAcctId = 3
SELECT SUM(FBalance) FROM TBKAccount#
WHERE FAcctId = 3
AND FMemId IN(SELECT FMemId FROM ##Member)
SELECT * FROM TBKAccount# AS A,TMemberCardAcctHist AS B
WHERE A.FCardId = B.FCardId
AND B.FBillType = 'DR'
AND abs(B.FInAmount - A.FBalance ) > 0.1
and a.facctid = b.facctid
101514.360000 + 35581.800000
SELECT 1037487.000000 - 2232.000000 - 999673.200000
SELECT * FROM TMemberCardOldAcctHist WHERE FCardId = 7035889468118637373
SELECT * FROM TMemberOldTransHist WHERE FCardId = 7035889468118637373
SELECT * FROM TMemberCardAcctHist WHERE FCardId = 7035889468118637373
SELECT * FROM TMemberCardAccount WHERE FCardId = 7035889468118637373
SELECT * FROM TBKAccount# WHERE FCardId = 7035889468118637373
select * from TMemberCard WHERE FCardId = 7035889468118637373
SELECT * FROM TMemberCard
SELECT * FROM TMemberOldTransHist WHERE FTransNo = '0006823'
SELECT * FROM CHONGQING_QIJIA_BK..gcm20 WHERE gct14c NOT IN(SELECT FTransNo FROM TMemberOldTransHist)
select * FROM TBKAccount# WHERE FCardId = 7035889468118637373
SELECT SUM(FBalance) FROM TBKAccount#
WHERE FCompId = dbo.FNCOmpId('005')
AND FAcctId = 3
SELECT * FROM