sql语句问题

happyrain2010 2013-03-07 03:20:54
一个表中一个字段存的是在用的编号 1,2,3,4.......这个编号随着业务用完了 就删除了!
求一条sql语句实现如下效果 1,3 返回2
1,2,3,4 返回5
总之返回的是表中没有的最小的正整数
感谢提供!
...全文
143 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
happyrain2010 2013-03-07
  • 打赏
  • 举报
回复
引用 1 楼 hjywyj 的回复:
SQL code?123declare @str varchar(10)set @str='1,3'select min(number) from master..spt_values where type='p' and number>0 and charindex(','+rtrim(number)+',',','+@str+',')<=0
怎么把列的值转成1,2,3你?
昵称被占用了 2013-03-07
  • 打赏
  • 举报
回复
select top 1 a.colname -1 as colname from tablename a where a.colname > 1 and not exists ( select 1 from tablename where colname = a.colname -1 ) order by a.colname
  • 打赏
  • 举报
回复
declare @str varchar(10)
set @str='1,3'
select min(number) from master..spt_values where type='p' and number>0 and charindex(','+rtrim(number)+',',','+@str+',')<=0

22,301

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧