I am trying to pass two 10 digit telephone number block using TSQL.
Lets say:
TelephoneNumber1: 1234560095
TelephoneNumber2: 1234561005
My Table consists of 3 columns:
ID, StartBlock, EndBlock
1, 5671231000, 5671232000
2, 1234561000, 1234562000
3, 2175551200, 2175551300
So what I am trying to do is find all the numbers between TelephoneNumber1
and TelephoneNumber2
and see if it exists between any records between StartBlock
and EndBlock
in the table.
In this example, it would find a number already in use in the second record because
when 1234560095
gets to 1234561000
, it will find it in already in use.
How do I accomplish this to find a number in use between the StartBlock and EndBlock?
declare @T table
(
ID int,
StartBlock bigint,
EndBlock bigint
)
insert into @T values
(1, 5671231000, 5671232000),
(2, 1234561000, 1234562000),
(3, 2175551200, 2175551300)
declare @TelephoneNumber1 bigint
declare @TelephoneNumber2 bigint
set @TelephoneNumber1 = 1234560095
set @TelephoneNumber2 = 1234561005
select *
from @T
where StartBlock <= @TelephoneNumber2 and
EndBlock >= @TelephoneNumber1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With