请教:如何更新这个字段?

jacky_hou 2003-10-28 01:54:17
表tab中有一个自动编号的字段ID,一个数据类型为char的字段out
现在out的情况是
1
2
3
4
5
null
null
...
问:如何将字段out中为null的值=max(out)+1
比如上面这个例子中,为null的部分将等于6
...全文
27 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-10-28
  • 打赏
  • 举报
回复
或:

declare @a int
update tab set @a=case when out is not null then out else @a+1 end,out=@a
sdhdy 2003-10-28
  • 打赏
  • 举报
回复
update tab set [out]=(select max([out]) from tab)+1 where [out] is null
pengdali 2003-10-28
  • 打赏
  • 举报
回复
update tab set out=(select max(cast(rtrim(out) as int))+1 from tab) where out is null

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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