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

82 lines
4.0 KiB

use KunMing_JuHao_ErJiLu
SELECT * FROM TImpMember
WHERE FMemNo = '7537'
--½»Ò×ÀúÊ·
select b.SV_ID bId,b.SV_NO,isnull(b.attaNo,'') attaNo,b.SV_ID,b.bill_status,b.BALANCE_DATE,b.ISCANCEL,b.OUT_DATE,b.BALANCE_AMT,b.AR_AMT,b.CASH_STRIKE_AMT,b.BANK_STRIKE_AMT,b.CARD_STRIKE_AMT,b.JF_STRIKE_AMT,b.DBQ_STRIKE_AMT,isnull(a.ASSOCIATORL_NO,'') ASSOCIATORL_NO,d.DEPT_NAME,c.CUST_NAME,c.HOME_TEL,c.MOBILE_TEL, itemDetail.sv_item_name itemName,itemDetail.amount itemAmt from MS_SVMASTER b left join MS_Associatorl a on (a.ASSOCIATORL_ID = b.ASSOCIATORL_ID) left join MS_CUSTOMER c on (c.CUST_ID = b.OBJ_ID )left join MS_Dept d on (b.DEPT_ID = d.DEPT_ID) left join ms_svitemdetail itemDetail on (itemDetail.sv_id = b.SV_ID) where b.bill_status = 6 and d.DEPT_CODE like '0%' and c.CUST_NO = '000150' and b.dept_id in (select dept_id from ms_dept where dept_code like '0%') and b.ar_amt >= 0.0 union all select b.SV_ID bId,b.SV_NO,isnull(b.attaNo,'') attaNo,b.SV_ID,b.bill_status,b.BALANCE_DATE,b.ISCANCEL,b.OUT_DATE,b.BALANCE_AMT,b.AR_AMT,b.CASH_STRIKE_AMT,b.BANK_STRIKE_AMT,b.CARD_STRIKE_AMT,b.JF_STRIKE_AMT,b.DBQ_STRIKE_AMT,isnull(a.ASSOCIATORL_NO,'') ASSOCIATORL_NO,d.DEPT_NAME,c.CUST_NAME,c.HOME_TEL,c.MOBILE_TEL, invb.item_name itemName ,invb.amount itemAmt from MS_SVMASTER b left join MS_Associatorl a on (a.ASSOCIATORL_ID = b.ASSOCIATORL_ID) left join MS_CUSTOMER c on (c.CUST_ID = b.OBJ_ID )left join MS_Dept d on (b.DEPT_ID = d.DEPT_ID) left join MS_INVBillDetail invb on (b.OUT_MATERIAL_ID = invb.bill_id) where b.bill_status = 6 and d.DEPT_CODE like '0%' and c.CUST_NO = '000150' and b.dept_id in (select dept_id from ms_dept where dept_code like '0%')
and b.ar_amt >= 0.0
order by b.SV_ID desc
--ÁƳÌ
SELECT I.SERVICEITEM_NO AS FItemNo,
I.SERVICEITEM_NAME AS FItemName,
M.ASSOCIATORL_NO AS FMemNo,
c.used_times + c.CANU_TIMES AS FPurTimes,
c.USED_TIMES AS FUsedPurTimes,
C.REMARK AS FMemo,
C.STD_JG AS FAdjustPrice,
C.BEGIN_DATE AS FCreateDate,
C.END_DATE AS FExpiredDate
INTO TImpMemberCourse
FROM MS_ServiceItem AS I,
MS_Associatorl AS M,
MS_AssociatorlDetail AS C
WHERE M.ASSOCIATORL_ID = C.ASSOCIATORL_ID
AND CANU_TIMES > 0
AND C.SERVICEITEM_ID = I.SERVICEITEM_ID
SELECT * FROM TImpMemberCourse
ALTER TABLE TImpMemberCourse ADD FMemId bigint,FCompId BIGINT,FId BIGINT
UPDATE A
SET A.FMemId = B.FMemId,
A.FCompId = B.FCompId,
A.FId = dbo.FNNewId()
FROM TImpMemberCourse AS A,TImpMember AS B
WHERE A.FMemNO = B.FMemNo
ALTER TABLE TImpMemberCourse ADD FItemId BIGINT
ALTER TABLE TImpMemberCourse ADD FCourseId BIGINT
UPDATE A
SET A.FItemId = B.FItemId,
A.FCourseId = B.FId
FROM TImpMemberCourse AS A,TCourse AS B,TItem AS I
WHERE A.FItemName = I.FName
AND I.FId = B.FItemId
SELECT * FROM TImpMemberCourse WHERE FItemid IS NULL
SELECT FItemName FROM TImpMemberCourse
GROUP BY FItemName
SELECT * FROM TItem WHERE FName = '¼ô·¢£¨ÎÞÕۿ۽׶η¢ÐÍʦ'
SELECT * FROM TItem
DROP TABLE TImpMemberCourse
SELECT * FROM TCourse
INSERT TMemberCourse(FId,FMemId,FCourseId,FMemPackId,FItemId,FCompId,FPurTimes,FUsedPurTimes,FPurAmount,FFreeTimes,FFreeAmount,FPurchaseDate,FExpiredDate,FBizType,FTransId,FArrear,FDurable,FMemo,FCalcMode,FAdjustPrice,FState)
SELECT FId,FMemId,FCourseId,0,FItemId,FCompId,FPurTimes,FUsedPurTimes,0,0,0,FCreateDate,FExpiredDate,'DR.Import',0,0,0,FMemo,1,FAdjustPrice,1
FROM TImpMemberCourse AS A
INSERT INTO TMemberCourseLog(FId,FMemId,FCardId,FCourseId,FItemId,FPackId,FTime,FInPurTimes,FInFreeTimes,FOutPurTimes,FOutFreeTimes,FRemainPurTimes,FRemainFreeTimes,FCompId,FBillType,FBizType,FBillId,FBillNo,FBillDetailId,FRecordTime,FMemo)
SELECT Id = FId,MemId = FMemId,CardId = 0,CourseId = FCourseId,ItemId = FItemId,PackId = 0,Time = getdate(),InPurTimes = FPurTimes,InFreeTimes =0,
OutPurTimes = FUsedPurTimes,OutFreeTimes = 0,RemainPurTimes = FPurTimes - FUsedPurTimes,RemainFreeTimes = 0,CompId = FCompId ,BillType = 'DR',BizType = 'Import',BillId = 0,BillNo = '',BillDetailId = 0,RecordTime = getdate(),Memo = 'ÀÏϵͳµ¼Èë'
FROM TImpMemberCourse AS A