how to validate records

  • I have Table_A in which data is imported from text file ..

    Table_A

    Ex:

    SID State ShortName Description UniqueId Year

    10001 VA Nut This is NUT 10010101 2001

    10001 PA Com This is Com A0010101 NULL

    10001 VA EOW This is Com 10010101 2008

    Table_B:

    BID Shortname SID

    5 NUT 10001

    6 Com 10001

    211 Eow 10001

    212 Eco 10001

    213 land 10001

    Table_C (Exclusive table):

    BmpId ExclusiveBmpId

    5 211

    5 212

    5 213

    6 211

    6 213

    7 211

    8 130

    211 5

    211 6

    211 7

    212 5

    212 6

    212 7

    213 5

    213 6

    213 7

    These are exclusive IDs

    TABLE_D (TblState)

    SID Stateid State

    10001 1 DC

    10001 2 DE

    10001 3 MD

    10001 5 NY

    10001 6 PA

    10001 7 VA

    10001 8 WV

    I joined Tables B, C and D and placed the results in tempTableZZ

    TempTable_ZZ

    BID ShortName EXID State

    5 NUT 211 VA

    5 NUT 212 VA

    5 NUT 213 VA

    6 Com 211 VA

    6 Com 212 VA

    6 Com 213 VA

    211 Eow 5 VA

    211 Eow 6 VA

    211 Eow 7 VA

    212 Eco 5 VA

    212 Eco 6 VA

    212 Eco 7 VA

    213 land 5 VA

    213 land 6 VA

    213 land 7 VA

    The validation check against TempTable_ZZ is where I am struggling to create. e.g., If the shortname in Table_A is "NUT" which its' BID which is located in table_B is 5, Then check if the BID is 5 and the EXID is either 211, 212, 213 in the TempTable_ZZ. If in TempTable_ZZ BID is 5 and the the EXID are any of the aforementioned then throw an error. Questions is, How do I do this?

  • I strongly recommend that you read the article at the first "Helpful Link" in my signature line below.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply