Sunday, November 21, 2010

TSQL Challenge 43 – Identifying incomplete segments and missing elements

The problem presented in this challenge is related to a validation requirement needed as part of an electronic data exchange process. There are two applications involved in this process. The “Sender” sends a ASCII file in a predefined format to the “Receiver”. The “Receiver” application accepts the files and inserts the data into a staging table. The following illustration shows how the data looks like.
Sample Data
Here is the sample data for this challenge.
Sr          val
----------- -------------------------
1           BS*AB1
2           SH*ABC*123
3           NM*ABC*123
4           NM*ABC*123
5           RF*ABC*123
6           BE*
7           BS*AB2
8           SH*ABC*123
9           NM*ABC*123
10          BS*AB3
11          SH*ABC*123
12          BE*
13          BS*AB4
14          SH*ABC*123
15          RF*ABC*123
16          BS*AB5
17          SH*ABC*123
18          RF*ABC*123
19          ZZ*ABC*123
20          ZZ*ABC*123
21          YY*ABC*123
22          BE*

Read more: Beyond Relational