Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Validating records

$
0
0

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:

Ex:

 

BID Shortname SID

5    NUT       10001       

6    Com       10001  

211  Eow       10001           

212  Eco       10001    

213  land      10001  

 

       

Table_C (Exclusive table):

 

Ex:

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)

 

Ex:

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 

 

Ex:

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?

 




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>