2016-03-17 64 views
1

我目前正在嘗試更新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 
+0

沒看到我的答案嗎? – cardmagik

+0

@cardmagik - 我試着運行我根據你的例子更新的代碼。它運行到'成功',但我沒有得到一個額外的錯誤日誌表,因爲我想。我還應該提到我的開發人員不在國內,所以在SQR方面我絕對是一個新手。 –

+0

DupFound在每條記錄後重置 - 當您檢查複製並寫入錯誤時,您在數據之外 - 基本上只檢查集合中的最後一條記錄。你應該做的是調用一個過程。我可以添加代碼,如果你喜歡下面,但它將不得不在幾個小時內從現在開始 – cardmagik

回答

0

這裏是一個編譯更正後的代碼:你

begin-procedure check-duplicates 

create-array name=SchlDuplicates 
    size=15 
Field=Val:Char 

BEGIN-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    

FROM PS_MICA_STSCHL_STG 
WHERE MICA_COMMON_APP_ID = $Application_ID 
END-SELECT 

    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 

!show 'MICA_SCH1_CEEBCD: ' $MICA_SCH1_CEEBCD ' MICA_SCH2_CEEBCD: '  $MICA_SCH2_CEEBCD 

    Let #I = 1 
    Let $DupFound = 'N' 
    While #I <= 13 and $DupFound = 'N' 
     Let #J = #I + 1 
     While #J <= 14 and $DupFound = 'N' 
      Get $Val1 from SchlDuplicates(#I) Val 
      Get $Val2 from SchlDuplicates(#J) Val 
      If $Val1 = $Val2 
      Show 'Found duplicates ' $Val1 ' ' $Val2 
      Let $DupFound = 'Y' 
      do Insert-Error 
      End-If 

      add 1 to #J 
     End-While 

     Add 1 to #I 
    End-While 



End-Procedure 

Begin-Procedure Insert-Error 

Let $Error_table = 'Duplicate Schools ' || $Val1 

BEGIN-SQL 
     INSERT INTO PS_MICA_ERROR_LOG 
     VALUES($Application_ID, 
      $App_export_dt, 
      $Error_table, 
      '') 

END-SQL 
End-procedure 
0

這使用你的代碼,並呼籲與重複每個記錄插入錯誤處理程序。這標誌着每一個dups記錄(但每個記錄只有一個)。如果您只希望所有記錄有一個錯誤,請告訴我。

begin-procedure check-duplicates 

create-array name=SchlDuplicates 
     size=15 
    Field=Val:Char 

BEGIN-SQL On-Error=give_warning 

SELECT 
School2_lookup_ceebcode 
School3_lookup_ceebcode 
School4_lookup_ceebcode 
College1_lookup_ceebcode 
College2_lookup_ceebcode 
College3_lookup_ceebcode 
TR_school_lookup_ceebcode 
TR_college1_lookup_ceebcode 
TR_college2_lookup_ceebcode 
TR_college3_lookup_ceebcode 
TR_2nd_school1_lookup_ceebcode 
TR_2nd_school2_lookup_ceebcode 
TR_2nd_school3_lookup_ceebcode 

    show 'School1_Lookup: ' &School1_Lookup_ceebcode ' School2_Lookup: ' &School2_Lookup_ceebcode 

     put &School1_lookup_ceebcode into SchlDuplicates(1) Val 
     put &School2_lookup_ceebcode into SchlDuplicates(2) Val 
     put &School3_lookup_ceebcode into SchlDuplicates(3) Val 
     put &School4_lookup_ceebcode into SchlDuplicates(4) Val 
     put &College1_lookup_ceebcode into SchlDuplicates(5) Val 
     put &College2_lookup_ceebcode into SchlDuplicates(6) Val 
     put &College3_lookup_ceebcode into SchlDuplicates(7) Val 
     put &TR_school_lookup_ceebcode into SchlDuplicates(8) Val 
     put &TR_college1_lookup_ceebcode into SchlDuplicates(9) Val 
     put &TR_college2_lookup_ceebcode into SchlDuplicates(10) Val 
     put &TR_college3_lookup_ceebcode into SchlDuplicates(11) Val 
     put &TR_2nd_school1_lookup_ceebcode into SchlDuplicates(12) Val 
     put &TR_2nd_school2_lookup_ceebcode into SchlDuplicates(13) Val 
     put &TR_2nd_school3_lookup_ceebcode 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 
       Show 'Found duplicates ' $Val1 ' ' $Val2 
       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 
END-SQL 

End-Procedure 

Begin-Procedure Insert-Error 

Let $Error_table = 'Duplicate Schools ' || $Val1 

BEGIN-SQL 
      INSERT INTO PS_MICA_ERROR_LOG 
      VALUES($Application_ID, 
       $App_export_dt, 
       $Error_table, 
       '') 

END-SQL 

end-procedure