比较ID编号为
0001至NNNN中间有些可能并不连续,就是说有些号可能并不存在。
现在我想每30个ID为一组,然后取出每个30个ID组的第1个号码为第30个号码,不知道应该如何做?
比如,假设0001-0030中间没有断号,而且连续,则我需要的就是0001-00030这种形式。
谢谢
0001至NNNN中间有些可能并不连续,就是说有些号可能并不存在。
现在我想每30个ID为一组,然后取出每个30个ID组的第1个号码为第30个号码,不知道应该如何做?
比如,假设0001-0030中间没有断号,而且连续,则我需要的就是0001-00030这种形式。
谢谢
解决方案 »
- 关于SQL2000性能监视的问题
- 关于几点优化经验的问题,我想不痛为什么,请高手举例论证此观点,谢谢~
- 能否实现这样的查询结果
- 数据筛选,麻烦大家帮助,跪谢!
- 在SQL查询分析器中,如何设置命令将已备份的数据强制还原到指定的数据库?
- SQL Server Profiler中碰到的一个疑难问题
- 日志传送出错“无法初始化”怎么回事?
- 一个有关全文索引的问题
- 在sql server2000中如何制作大批量的数据并把它倒入数据库?
- 100分求助,请问一sqlserver链接远程服务器的问题!
- 100分--如何剔除不合规律的行?
- UPDATE1万条记录的DATETIME字段,结果因为输错了日期,全部弄错了,怎么恢复?
@value int
as
declare @MaxValue int
declare @MaxValueT intdeclare @test table(Rowid int)
insert @test select 1
union all select 2
union all select 3
union all select 4
union all select 5
union all select 8
union all select 9
union all select 15
union all select 16declare @result table(start int,[end] int,startA varchar(10),[endA] varchar(10))select *,id=identity(int,1,1) into #tmp from @test order by rowid
select @MaxValue=max(id) from #tmp where id % @value=0
select @MaxValueT=max(id) from #tmp
if @MaxValue is null
insert @result select min(id) a,max(id) b, ltrim(min(id)) c,ltrim(max(id)) d from #tmp
else
begin
insert @result select id,0,'','' from #tmp where id<=@MaxValue and id %@value=1 order by id
update @result set [end]=start+@value-1
if @MaxValue<@MaxValueT
insert @result select @MaxValue+1 a,@MaxValueT,'',''
end
update @result set starta=rowid from #tmp where start=id
update @result set [enda]=rowid from #tmp where [end]=id
select startA,endA from @result
drop table #tmp============================
groupt 3