表 a 中有一列规律字符
F000001
F000002
F000003
....
F232490如果传一入1个首字符F000251 和 1个间隔数 如 50在access中,要查询出如下效果
F000251-F000300
F000301-F000350
F000351-F000400
....
F005201-F005250如果传入F000251,间隔数是40
效果如下:
F000251-F000290
F000291-F000330
.....
F000001
F000002
F000003
....
F232490如果传一入1个首字符F000251 和 1个间隔数 如 50在access中,要查询出如下效果
F000251-F000300
F000301-F000350
F000351-F000400
....
F005201-F005250如果传入F000251,间隔数是40
效果如下:
F000251-F000290
F000291-F000330
.....
from a
where 有一列>='F000251'
and (val(mid(有一列,2))-val(mid('F000251',2))) mod 40=0
declare @a table([code] varchar(7))
declare @i int
select @i = 1
while @i <= 400
begin
insert into @a select 'F'+right('00000'+ltrim(@i),6)
select @i = @i + 1
endselect min([code])+'-'+max([code])
from @a
where [code]>='F000251'
group by (cast(right([code],6) as int) -1)/50
-----------------------
F000251-F000300
F000301-F000350
F000351-F000400
min([code])+'-'+max([code])
from
tb
where
[code]>='F000251'
group by
(cast(right([code],6) as int) -1)/50ACCESS的不清楚
from @a
where [code]>='F000251'
group by (cast(right([code],6) as int) -1)/50