I want to do something similar to below. I have the pseudo-logic below. Just wonder how to implement this:
delete B
from
TableA A with (nolock), TableB B with (nolock) 
where A.BeginNumber <= B.startipnum and A.Endnumber >= B.endipnum
delete A
from
TableA A with (nolock), TableB B with (nolock) 
where A.BeginNumber => B.startipnum and A.Endnumber <= B.endipnum
update B
set endipnum = startnumber - 1
from
TableA A with (nolock), TableB B with (nolock) 
where A.BeginNumber < B.startipnum and A.Endnumber <= B.endipnum
update B
set startipnum = endnumber + 1
from
TableA A with (nolock), TableB B with (nolock) 
where A.BeginNumber >= B.startipnum and A.Endnumber > B.endipnum
Sample Data
Table A
BeginNumber EndNumber
----------      ---------
16843009    16843009
16843009    16843010
16843009    16843013
16843009    16843016
33686020    33686024
TableB
startipnum  endIPNum
----------      ---------
1488047401  1488047401
1504824617  1873923369
1890700585  1907477801
1924255017  2142358825
2159136041  2276576553
There are no columns to join on between the 2 tables. Please help.
Thanks!