1

我目前正在尝试更新 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
4

2 回答 2

0

这将使用您的代码并为每个重复的记录调用插入错误例程。这会用重复标记每条记录(但每条记录只有一个)。如果您只希望所有记录出现一个错误,请告诉我。

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
于 2016-03-17T18:42:55.493 回答
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
于 2016-04-08T18:09:22.567 回答