Select record between two IP ranges
<p>I have a table which stores a <code>ID</code>, <code>Name</code>, <code>Code</code>, <code>IPLow</code>, <code>IPHigh</code> such as:</p>

<pre><code>1, Lucas, 804645, 192.130.1.1, 192.130.1.254
2, Maria, 222255, 192.168.2.1, 192.168.2.254
3, Julia, 123456, 192.150.3.1, 192.150.3.254
</code></pre>

<p>Now, if I have an IP address <code>192.168.2.50</code>, how can I retrieve the matching record?</p>

<p><strong>Edit</strong></p>

<p>Based on Gordon's answer (which I'm getting compilation errors) this is what I have:</p>

<pre><code>select PersonnelPC.*
from (select PersonnelPC.*,
             (
              cast(parsename(iplow, 4)*1000000000 as decimal(12, 0)) +
              cast(parsename(iplow, 3)*1000000 as decimal(12, 0)) +
              cast(parsename(iplow, 2)*1000 as decimal(12, 0)) +
              (parsename(iplow, 1))
             ) as iplow_decimal,
            (
              cast(parsename(iphigh, 4)*1000000000 as decimal(12, 0)) +
              cast(parsename(iphigh, 3)*1000000 as decimal(12, 0)) +
              cast(parsename(iphigh, 2)*1000 as decimal(12, 0)) +
              (parsename(iphigh, 1))
             ) as iphigh_decimal
      from PersonnelPC
     ) PersonnelPC
where 192168002050 between iplow_decimal and iphigh_decimal;
</code></pre>

<p>but this gives me an error:</p>

<pre><code>Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.
</code></pre>

<p>Any ideas?</p>