日期:2014-05-17 浏览次数:20523 次
select number from mster..spt_values s left join t where s.number=t.value and type='p' where t.value is null
------解决方案--------------------
修改下,把最小值最大值加上。。。
declare @i int declare @n int declare @min int declare @max int set @i=0 --生成数据最小值 set @n=10000 --生成数据最大值 set @min=5000 --查询范围最小值 set @max=10000 --查询范围最大值 CREATE TABLE #t( [ID] [int] IDENTITY(1,1) NOT NULL, [number] [int] NULL ) CREATE TABLE #y( [ID] [int] IDENTITY(1,1) NOT NULL, [number] [int] NULL ) ---插入测试数据 insert into #t select 1 union all select 2 union all select 3 union all select 4 while (@i<=@n) begin insert into #y ([number]) values(@i) set @i=@i+1 end ---查询测试结果 select y.number from #y y left join #t T on y.number=T.[number] where y.number>=@min and y.number<=@max and T.[number] is null drop table #t drop table #y
------解决方案--------------------