我目前正在嘗試更新SQR以檢查給定記錄內各個列之間的重複值。我們允許在表中輸入重複項,但是我們希望在打破下一個程序時檢查錯誤標誌。檢查SQR中的重複內容
ID - 1 Var1 - 3809 Var2 - 3809
ID - 2 Var1 - NULL Var2 - NULL
ID - 3 Var1 - 5204 Var2 - 3809
在這種情況下,ID 1將檢查錯誤標誌,其他兩個不會。我不能簡單地檢查值,因爲我需要檢查12個不同的列。任何幫助將非常感激。
謝謝! 丹
我嘗試下面的代碼,它編譯,但不記錄重複
begin-procedure check-duplicates
create-array name=SchlDuplicates
size=15
Field=Val:Char
BEGIN-SQL
SELECT
MICA_SCH1_CEEBCD
MICA_SCH2_CEEBCD
MICA_SCH3_CEEBCD
MICA_SCH4_CEEBCD
MICA_COL1_CEEBCD
MICA_COL2_CEEBCD
MICA_COL3_CEEBCD
MICA_TRSCH1_CEEBCD
MICA_TRCOL1_CEEBCD
MICA_TRCOL2_CEEBCD
MICA_TRCOL3_CEEBCD
MICA_TSSCH1_CEEBCD
MICA_TSSCH2_CEEBCD
MICA_TSSCH3_CEEBCD
put MICA_SCH1_CEEBCD into SchlDuplicates(1) Val
put MICA_SCH2_CEEBCD into SchlDuplicates(2) Val
put MICA_SCH3_CEEBCD into SchlDuplicates(3) Val
put MICA_SCH4_CEEBCD into SchlDuplicates(4) Val
put MICA_COL1_CEEBCD into SchlDuplicates(5) Val
put MICA_COL2_CEEBCD into SchlDuplicates(6) Val
put MICA_COL3_CEEBCD into SchlDuplicates(7) Val
put MICA_TRSCH1_CEEBCD into SchlDuplicates(8) Val
put MICA_TRCOL1_CEEBCD into SchlDuplicates(9) Val
put MICA_TRCOL2_CEEBCD into SchlDuplicates(10) Val
put MICA_TRCOL3_CEEBCD into SchlDuplicates(11) Val
put MICA_TSSCH1_CEEBCD into SchlDuplicates(12) Val
put MICA_TSSCH2_CEEBCD into SchlDuplicates(13) Val
put MICA_TSSCH3_CEEBCD into SchlDuplicates(14) Val
Let #I = 1
Let $DupFound = 'N'
While #I <= 13 and $DupFound = 'N'
Let #J = #I + 1
While #J <= 14
Get $Val1 from SchlDuplicates(#I) Val
Get $Val2 from SchlDuplicates(#J) Val
If $Val1 = $Val2
let $DupFound = 'Y'
do Insert-Error
End-If
add 1 to #J
End-While
Add 1 to #I
End-While
FROM PS_MICA_STSCHL_STG
WHERE MICA_COMMON_APP_ID = $Application_ID || $Val1
END-SQL
End-Procedure
Begin-Procedure Insert-Error
If $DupFound = 'Y'
Let $Error_table = 'Duplicate Schools'
End-If
BEGIN-SQL
INSERT INTO PS_MICA_ERROR_LOG
VALUES($Application_ID,
$App_export_dt,
$Error_table,
'')
END-SQL
end-procedure
沒看到我的答案嗎? – cardmagik
@cardmagik - 我試着運行我根據你的例子更新的代碼。它運行到'成功',但我沒有得到一個額外的錯誤日誌表,因爲我想。我還應該提到我的開發人員不在國內,所以在SQR方面我絕對是一個新手。 –
DupFound在每條記錄後重置 - 當您檢查複製並寫入錯誤時,您在數據之外 - 基本上只檢查集合中的最後一條記錄。你應該做的是調用一個過程。我可以添加代碼,如果你喜歡下面,但它將不得不在幾個小時內從現在開始 – cardmagik