在我的應用程序中,我有一個名爲「每日例外報告」的報告,用於顯示ISA的例外情況。在這個表格中,我看到重複的條目(報告中恰好有兩個相同的行)。在將結果集插入表中時複製
技術細節。
例外情況報告將顯示在table
中的可用數據中,該數據稱爲ExceptionFirstReported
,其中有重複的條目。 Insert Statement
用於將insert
排成ExceptionFirstReported
是stored procedure
usp_Refresh_Daily_Exception_Report
。
INSERT INTO ExceptionFirstReported(
InvestorReference, ExceptionReason, First_Reported_Date, RelativeRef)
SELECT InvestorReference, ExceptionReason, Dateupdated, RelatedInvRef FROM (
SELECT * FROM DailyExceptionReport As DER
WHERE NOT EXISTS
(SELECT ExcepRptd.InvestorReference
FROM ExceptionFirstReported AS ExcepRptd
WHERE DER.InvestorReference = ExcepRptd.InvestorReference
AND DER.ExceptionReason = ExcepRptd.ExceptionReason
AND DER.RelatedInvRef = ExcepRptd.RelativeRef))
AS CI
JOIN currentISAs AN CI.InvestorReference = Status_Inv_Ref
我們認爲可以在兩種不同的情況下,沒有重複的條目這個說法,因爲不會有行中具有相同的InvestorReference
,ExceptionReason
和`RelatedInvRef。
但是我們有重複輸入。這是用於將行插入table
的唯一insert
聲明。 表DailyExceptionReport
和currentISAs
以前不包含重複項。
上述插入查詢已在存儲過程「usp_refresh_dailyreport」中調用,並且SP僅在一個週期中執行過一次。
@returnvalue = Exec的usp_refresh_dailyreport
如果@返回值= 1
然後
InvestorReference ExceptionReason First_reported_dt
Recent_reported_dt relativeref report_gen_date
442643169642無餘額2012-04-11 9時54分:00
2012-05-04 23:58:00 NULL
442643169642>一ISA 2012-04-21六點30分00秒2012-04-23二十三點58分00秒452750423823 NULL
442643169642>一ISA 2012-04-21六點30分00秒
2012-04-23 23:58:00 452750423823 NULL
上述'ExceptionFirstReported'表中的數據的最後兩行是相同的,並且包含相同的relativeref(非空)。道歉傢伙'relativeref'不是空字段,但我可能會像第一行一樣保留空白數據。
thnk好友。問題是我無法向表中添加索引,因爲在向表中添加主索引時,如果插入查詢嘗試插入副本,則過程將停止發生錯誤。我正在爲銀行直播系統工作。這份報告必須每天生成。 – user1373129
@Angelo Neuschitzer thnk u ..讓我檢查ABT的線程.. – user1373129