需求贴:
http://topic.youkuaiyun.com/u/20110708/17/334a25b1-ab00-4fab-bdfa-2fcd319411a4.html
colname
------------
12/31/75
34/67/94/113
*/
例如上表,只有一个字段nvarchar类型的。
--第二种方法借助master..spt_values --测试数据 declare @table table (colname nvarchar(12)) insert into @table select '12/31/75' union all select '34/67/94/113' union all select '1/56/3/16' union all select '34/23/12/24' union all select '90/34/45/47' select * from @table --设置参数 declare @i int;set @i=70 --进行搜索 select a.* from @table a left join master..spt_values b on charindex('/'+ltrim(b.number)+'/','/'+a.colname+'/')>0 where b.[type]='P' and b.number is not null and number between @i-10 and @i+10 --运行结果 /* colname ------------ 12/31/75 34/67/94/113 */
http://topic.youkuaiyun.com/u/20110708/17/334a25b1-ab00-4fab-bdfa-2fcd319411a4.html
主要描述:
/*colname
------------
12/31/75
34/67/94/113
*/
例如上表,只有一个字段nvarchar类型的。
搜索的时侯输入一个数值15,那么搜索的范围就是5-25,第一行的12符合这个范围,第一行就搜出来。
例如输入70,第一行的75,和第二行的67都符合搜索范围。
--第二种方法借助master..spt_values --测试数据 declare @table table (colname nvarchar(12)) insert into @table select '12/31/75' union all select '34/67/94/113' union all select '1/56/3/16' union all select '34/23/12/24' union all select '90/34/45/47' select * from @table --设置参数 declare @i int;set @i=70 --进行搜索 select a.* from @table a left join master..spt_values b on charindex('/'+ltrim(b.number)+'/','/'+a.colname+'/')>0 where b.[type]='P' and b.number is not null and number between @i-10 and @i+10 --运行结果 /* colname ------------ 12/31/75 34/67/94/113 */