怎么知道一列int型的数字是否连续?????????????
RT 问题点数:20、回复次数:4Top
1 楼YiZhiNet(九斤半)回复于 2006-09-02 10:23:07 得分 20
参考:
reate table test( col char(3))
insert test
select '001' union all
select '002' union all
select '003' union all --注意“004”,“005”没有。。
--select '004' union all
--select '005' union all
select '006' union all
select '007'
select * from test
select top 1 right(1000 + cast(col as int) + 1,3) as 断号 from test A
WHERE NOT EXISTS(SELECT COL FROM test B WHERE CAST(A.col AS INT)+1=CAST(B.col AS INT))
drop table testTop
2 楼liangpei2008(笑青天)回复于 2006-09-02 10:28:41 得分 0
相关子查询!Top
3 楼xyxfly(All things are difficult before they are easy.)回复于 2006-09-02 10:33:27 得分 0
可以用一列连续的去连接Top
4 楼xyxfly(All things are difficult before they are easy.)回复于 2006-09-02 10:39:50 得分 0
create table t1(a int)
insert t1
select 1 union all
select 3 union all
select 4 union all
select 5
select id=identity(int,1,1),* into #T from t1
select * from #T left join t1 on #T.id=t1.a
id a a
----------- ----------- -----------
1 1 1
2 3 NULL
3 4 3
4 5 4
有空说明不连续
不过晕,不一定从1开始
Top




