CHARINDEX查询类似500*500相差20的数据




create table temp
(id int identity(1,1)  not null,
type1 nvarchar(20) )


insert into temp (type1)  values('500*500')
insert into temp (type1)  values('510*500')
insert into temp (type1)  values('510*520')
insert into temp (type1)  values('510*1000')
insert into temp (type1)  values('10*500')


declare @par nvarchar(20) 
select @par=20


select * from temp
where substring(type1,0,CHARINDEX('*',type1)) between 500-@par and 500+@par 
and substring(type1,CHARINDEX('*',type1)+1,len(type1)) between 500-@par and 500+@par 


id type1
2 500*500
3 510*500
4 510*520

你可能感兴趣的:(CHARINDEX查询类似500*500相差20的数据)