testTable :
id_start id_end
--------- ----------
1 10
11 14
15 30
38 45
50 60
-- 在页面上输入一个区间的值, 如 开始:30 结束:50
-- 要判断 30~50 这个区间内的所有数字(30,31,32,33,...,50)是否都存在testTable 表内
-- 输出不存在的数据
-- =============================================
BEGIN
declare @start int
declare @end int
set @start=30
set @end=50
while(@start <= @end)
begin
if exists(select * from testTable where @start between startnum and endnum)
begin
print convert(varchar(20),@start)+':exists';
end
else
begin
print convert(varchar(20),@start)+':not exists';
end
set @start = @start + 1
end
END