Skip to content
Advertisement

Two intervals coincide at some point in SQL-Server

How to know if two intervals coincide at some point? I have two tables that store two intervals where the values ​​mean meters.

  • The first interval corresponds to geological codes (VBv, P4, etc).
  • The second interval corresponds to samples.

They are connected through a field called Hole ID.



enter image description here

I need all the sample ranges that match the code ranges, putting a certain code as a parameter.

What I have tried: I built a query that checks if the “from” or “to” match. I also check if any interval is contained in another.



This works for the following situations:

enter image description here

enter image description here

But when there is no match in the “from” and “to” and one interval is not contained in the other, I don’t know how to solve it.

enter image description here

Advertisement

Answer

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement