我想修改一个表中前n条,比如前10条记录的某个字段的值,请问该如何做。
解决方案 »
- 如何获得页面文件和注册表详细信息
- delphi 中计算字符长度的函数是什么啊?急
- Runtime error 105 这是什么错误?
- 写了一个最简单的DCOM,显示一个表的内容,可是客户端提示“拒绝访问”
- 请问如何完全编译程序?(30分相送)急!急!急!
- 请问哪儿有DBGridEH 网格控件DELPHI6的版本下载,具体点!
- ******** 请登记一下税率吧 谢谢!!!!!!!!!!!!!!!!!!!
- 土问:这个窗口是怎么建立的?
- 如何在DBGridEh中设置某个CELL的字体?---忙晕头了,没心思自己找了,哪位告诉我?
- 如何播放WAV声音文件?在线等待!
- 一个窗体中三个avi文件同时播放,该怎么做?
- 系统托盘图标在进程结束后不自动消失问题,急求解答......请高手帮忙谢谢!
update 表名 set 字段=100 where 字段 in(select top 10 字段 from 表名 order by 字段)
不能用的话楼主可以定义一个变量控制
类似这样:
var
i:integer;
begin
i:=1;
if table1.Active = false then
table1.Open;
with table1 do
begin
First;
while not Eof do
begin
if i>10 then
Last
else
begin
Edit;
FieldByName('字段名').AsString := 'newvalue';
Post;
i:=i+1;
Next;
end;
end;
end;
end;
update 表名 set 字段=100 where 字段 in(select top 10 字段 from 表名 )
其中:
1)字段为关键字段,可以是组合关键字,如果是组合关键字,则将各组合关键字转为字符类型连接起来作为一个字段,另外,在“select top 10 字段”中的字段也是同样是组合关键字转为字符串类型的连接。
2)不需亚有order by语句,不打乱已有的排序。
这钟方法相当于先取出前10条,然后再依次比较表中的每一条,如果和此10条相同,则满足条件,不过,因为没有打乱原来表的顺序,所以,只会比较表中的前10条数据。 先不结帖,还有别的方法么?一起讨论一下。
测试ms-sql servercreate table abc (id int,title varchar(100))go
insert into abc
select 1,'11111'
union select 2,'11111'
union select 3,'11111'
union select 4,'11111'
union select 5,'11111'
union select 6,'11111'
union select 7,'11111'
union select 8,'11111'
union select 9,'11111'
union select 10,'11111'
union select 11,'11111'
union select 12,'11111'
union select 13,'11111'
union select 14,'11111'
union select 15,'11111'
union select 16,'11111'
union select 17,'11111'
union select 18,'11111'
union select 19,'11111'
union select 20,'11111'goselect * from abc
godeclare @ID int
declare @icount int
declare mm_Cursor scroll cursor for select [id] from abcset @Icount = 0
open mm_Cursor
fetch next from mm_Cursor into @ID
while (@@fetch_status = 0) and (@icount<10)
begin
update abc set title='2222222' where [id]=@ID fetch next from mm_Cursor into @ID
set @Icount = @iCount+1
end
close mm_cursor
deallocate mm_cursor
select * from abc