日期:2014-05-18 浏览次数:20690 次
create table tb(序号 int,价格 varchar(20))
insert into tb select 1,'100,150,400,450,668'
insert into tb select 2,'350,510,600,750,768'
insert into tb select 3,'250,450,460,550,668'
go
declare @min int,@max int
set @min=200
set @max=400 --你可以改变这两个值
select distinct 序号 from(
select a.序号,substring(a.价格,b.number,charindex(',',a.价格+',',b.number+1)-b.number)价格
from tb a,master..spt_values b
where b.type='p' and b.number<=len(a.价格) and substring(a.价格,b.number,1)<>',' and substring(','+a.价格,b.number,1)=','
)t where 价格 between @min and @max
/*
序号
-----------
1
2
3
(3 行受影响)
*/
go
drop table tb
------解决方案--------------------
合并拆分列 N多
------解决方案--------------------
lz是否可以考虑在程序端实现呢。
非要在数据库里实现的话。效率不一定会高。。
------解决方案--------------------
拆了再查!