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

Finidng the missing segments and return to the output

$
0
0

Hello All,

I am working on finding the missing segments which doesn't have a code value. I have 2 tables, Line and Code.

In the line table I have below columns

Line_ID                  BeginMeasure                   EndMeasure

1                                0                                      100

2                                0                                      200

3                                0                                      300

In the code table I may have multiple records for each line

Line_ID                       BeginMeasure                  EndMeasure                   code

1                                  12                                    30                                    3

1                                   40                                   50                                    4

2                                  0                                      150                                  6

3                                  30                                    300                                  8

Here I need to find out the segments which doesn't have a code value. For example, for Line_ID 1 in the code table we dont have a value for the code for 0 -12, 30 - 40 and 50 - 100 segments and for Line_ID 2, we dont have code for 150 - 200 segment. I want the  records which doesn't have code value defined in the output result set and the expected result set should be like below

Line_ID                           BeginMeasure                     EndMeasure

1                                        0                                            12

1                                        30                                          40

1                                        50                                           100

2                                       150                                          200

3                                         0                                             30

Any code suggestions/help is greatly appreciated.

Thanks so much


Viewing all articles
Browse latest Browse all 12890

Trending Articles



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