这条sql语句应该怎么写???急!大虾请进!

jamex 2000-08-25 01:56:00
有如下一张表:
有3个字段:No(string)、Name(string)、 Age(int)

我希望用一个sql语句实现这个功能: 更新所有记录的No字段,使第1条记录的No值为'100',第2条记录的No值为'101',第3条记录的No值为'102',第4条记录的No值为'103',.......依次类推!!

小弟冥思苦想,不得其解,望大虾救我!!!
...全文
309 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kradwang 2000-10-12
  • 打赏
  • 举报
回复
whitesky已经回答了是对的给他加分吧
tanghuan 2000-10-12
  • 打赏
  • 举报
回复
游标的速度够你受,如果要处理一个有2-3万行的游标,你可以睡上一觉后再看看他完成没有
呵呵
zzj 2000-10-11
  • 打赏
  • 举报
回复
还不简单,你新添加一个字段将他的种子设置成100,步长设置为1,然后用新字段值去更新NO字段就对了,用完后删除新建的字段
jamex 2000-10-10
  • 打赏
  • 举报
回复
to fxx:
rownum是指什么?
ms sql server 7好像不支持
WhiteSky 2000-10-10
  • 打赏
  • 举报
回复
Declare UpdateNoCursor as cursor for
select no,name,age from YourTableName
declare @NoVal INT
set @NoVal=100
open UpdateNoCursor
fetch next from UpdateNoCursor
while @@fetch_status=0
begin
update YourTableName set no=convert(char(3),@NoVal)
fetch next from UpdateNoCursor
set @NoVal=@NoVal+1
end
close UpdateNoCursor
deallocate UpdateNoCursor

WhiteSky 2000-10-10
  • 打赏
  • 举报
回复
Declare UpdateNoCursor as cursor for
select no,name,age from YourTableName
declare @NoVal INT
set @NoVal=100
open UpdateNoCursor
fetch next from UpdateNoCursor
while @@fetch_status=0
begin
update YourTableName set no=@NoVal
fetch next from UpdateNoCursor
set @NoVal=@NoVal+1
end
close UpdateNoCursor
deallocate UpdateNoCursor

tanghuan 2000-10-10
  • 打赏
  • 举报
回复
假定表为Table1 主键为NO 长度3

create table #table_temp (RowNo int IDENTITY(100,1),NO char(3))

insert into #table_temp (NO)
select NO
from Table1

update Table1
set Table1.NO=convert(char(3),RowNo)
from Table1,#table_temp
where Table1.NO=#table_temp.NO
tanghuan 2000-10-10
  • 打赏
  • 举报
回复
assume that name of ur table is Table1 and primary key is column name NO

create table #table_temp(RowNo int IDENTITY(100,1),NO char(3))
insert into #table_temp (NO)
select NO from Table1

update Table1
set Table1.NO=convert(char(3),RowNo)
from Table1,#table_temp
where Table1.NO=#table_temp.NO
Fxx 2000-08-27
  • 打赏
  • 举报
回复
update table_name set no=(rownum+100);
我已经试过肯定可以

jamex 2000-08-25
  • 打赏
  • 举报
回复
to LanZheng:
原来的NO值是不规则的字符串。

我用的是ms sql server 7
siclj 2000-08-25
  • 打赏
  • 举报
回复
update table set no=to_char(rownum+100)
LaoZheng 2000-08-25
  • 打赏
  • 举报
回复
你原来的NO是什么值?
jamex 2000-08-25
  • 打赏
  • 举报
回复
没有人知道吗????

34,575

社区成员

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

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