求一SQL语句。

wf2091139 2007-03-16 10:54:22
求一 SQL 的 update的语句。
比如修改某字段(field) 改为一种递增的字符,由用户提供起点和终点。
修改结果:
004
005
....
010
011
....
059


不知道 update 语句能否实现,最好不要用多条语句来实现。
...全文
161 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
alter table t drop column feild
alter table t add feild int identity(4,1)
wf2091139 2007-03-16
  • 打赏
  • 举报
回复
to: Yang_(扬帆破浪)

谢谢 !
Yang_ 2007-03-16
  • 打赏
  • 举报
回复
--环境和参数
declare @t table (id int,a varchar(10))

insert @t select 1,''
union all select 2,''
union all select 3,''
union all select 4,''
union all select 5,''
union all select 6,''
union all select 7,''

declare @Beg varchar(10)
set @Beg='004'

--开始处理
declare @a varchar(10)
set @a=right('000'+rtrim(cast(@beg as int)-1),3)
update @t
set @a=right('000'+rtrim(cast(@a as int)+1),3),a=@a

--显示结果
select * from @t

--结果
id a
----------- ----------
1 004
2 005
3 006
4 007
5 008
6 009
7 010

(所影响的行数为 7 行)

wf2091139 2007-03-16
  • 打赏
  • 举报
回复
没有什么修改了,某个表的某个字段值依次(假如按ID排序)递增 如
004
005
....
010
011
....
059

只不过递增量不是简单的整数。
mengmou 2007-03-16
  • 打赏
  • 举报
回复
需求不明确。

34,837

社区成员

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

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