CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  基础类

怎么知道一列int型的数字是否连续?????????????

楼主sqlaqandy(SQLY)2006-09-02 10:18:53 在 MS-SQL Server / 基础类 提问

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

相关问题

关键词

得分解答快速导航

  • 帖主:sqlaqandy
  • YiZhiNet

相关链接

  • SQL Server类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo