对查询结果中的某个空字段附值?

sssyyy 2002-05-14 10:49:35
查询排序代码:
begin
rep_infor.resultQuery.Close;
rep_infor.resultQuery.SQL.Clear;
if (resultcombobox3.Text=floattostr(3)) then
rep_infor.resultQuery.SQL.Add('select top 3 号码,姓名,性别,单位,项目名称,成绩,得分 from perinfor_input')
else
if (resultcombobox3.Text=floattostr(4)) then
rep_infor.resultQuery.SQL.Add('select top 4 号码,姓名,性别,单位,项目名称,成绩,得分 from perinfor_input ')
else
if (resultcombobox3.Text=floattostr(5)) then
rep_infor.resultQuery.SQL.Add('select top 5 号码,姓名,性别,单位,项目名称,成绩,得分 from perinfor_input')
else
if (resultcombobox3.Text=floattostr(6)) then
rep_infor.resultQuery.SQL.Add('select top 6 号码,姓名,性别,单位,项目名称,成绩,得分 from perinfor_input');
rep_infor.resultQuery.SQL.Add('where 项目名称=:items and 性别=:sex order by 成绩 desc');
rep_infor.resultQuery.Parameters.ParamByName('items').Value:=sj;
rep_infor.resultQuery.Parameters.ParamByName('sex').Value:=xb;
rep_infor.resultQuery.Open;
end;
end;
rep_infor.resultQuery.First;
rep_infor.resultQuery.Edit;
下面开始对排出的顺序中的‘得分’字段添加数值。//错误之处?请指点
目的是为了按顺序不同给不同的分值,将排序的所有记录都附值。
begin
while not rep_infor.resultQuery.Eof do
begin
inc(row);
if row=1 then
rep_infor.resultQuery.FieldByName('得分').AsInteger:=7;
if row=2 then
rep_infor.resultQuery.FieldByName('得分').AsInteger:=5;
if row=3 then
rep_infor.resultQuery.FieldByName('得分').AsInteger:=4;
if row=4 then
rep_infor.resultQuery.FieldByName('得分').AsInteger:=3;
if row=5 then
rep_infor.resultQuery.FieldByName('得分').AsInteger:=2;
if row=6 then
rep_infor.resultQuery.FieldByName('得分').AsInteger:=1;
end;
rep_infor.resultQuery.Post;
rep_infor.resultQuery.Next;
end;
...全文
63 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
短歌如风 2002-05-14
  • 打赏
  • 举报
回复
最多只会查询出6条记录(Select Top 6 ...)怎么会“循环了6次之后”呢?如果row是局部变量,根本不需要复位。
很多DBMS的“排序查询”(带有Oder by)是不可修改的,SQL Server好象就是如此。最好改用Update语句或改用UpdateSQL控件进行修改。

____ ____
\ p \ / g /
\ l \_/ n /
\ a o /
\ i s /
\ n /
\_/
moodboy 2002-05-14
  • 打赏
  • 举报
回复
你的row怎样来的?你可以把if语句该为:
case row of
1:……;
2:……;
……
6:……
else
row:=初值;
end;
del_c_sharp 2002-05-14
  • 打赏
  • 举报
回复
这样改一下,更简单些
begin
rep_infor.resultQuery.Close;
rep_infor.resultQuery.SQL.Clear;
rep_infor.resultQuery.SQL.Add('select top '+resultcombobox3.Text+' 号码,姓名,性别,单位,项目名称,成绩,得分 from perinfor_input');
rep_infor.resultQuery.SQL.Add('where 项目名称=:items and 性别=:sex order by 成绩 desc');
rep_infor.resultQuery.Parameters.ParamByName('items').Value:=sj;
rep_infor.resultQuery.Parameters.ParamByName('sex').Value:=xb;
rep_infor.resultQuery.Open;
end;
end;
rep_infor.resultQuery.First;
rep_infor.resultQuery.Edit;




begin
while not rep_infor.resultQuery.Eof do
begin
inc(row);
rep_infor.resultQuery.FieldByName('得分').AsInteger:=7-row;
if row=6 then row:=0;
end;
rep_infor.resultQuery.Post;
rep_infor.resultQuery.Next;
end;


sssyyy 2002-05-14
  • 打赏
  • 举报
回复
第一次用inc,不知如何复位,放在何处?
谢谢。
日总是我哥 2002-05-14
  • 打赏
  • 举报
回复
inc(row); 你不断inc,要是循环了6次之后怎么办呢?

你应该对它作复位(Reset)处理

另外,你可以对上面的if部分代码简简一下,那样真的很~~~~~
sssyyy 2002-05-14
  • 打赏
  • 举报
回复
我用的是access数据库,也不行吗。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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