通过查询表f1得到DBGRID1的内容:
code name
001 小张
002 小强
210 王力
...........数据库中有成绩表f2
code a1(课程) a2(成绩)
001 英语 65
001 数学 30
210 英语 56
210 数学 50
...............我想选中DBGRID1中多行(例如选种001和210行),让后点查询按扭在DBGRID2中显示
001 英语 65
001 数学 30
小计 95
210 英语 56
210 数学 50
小计 106
合计 201
主要是参数传输的问题,我用一个label显示在DBGRID1中选中的字符,我只想传输‘001’或‘002’
但鼠标点击到英语或数学上是,显示的是英语或数学,怎么样才能只让他传输code 列的数据呢(要能同时选中多行进行查询)
code name
001 小张
002 小强
210 王力
...........数据库中有成绩表f2
code a1(课程) a2(成绩)
001 英语 65
001 数学 30
210 英语 56
210 数学 50
...............我想选中DBGRID1中多行(例如选种001和210行),让后点查询按扭在DBGRID2中显示
001 英语 65
001 数学 30
小计 95
210 英语 56
210 数学 50
小计 106
合计 201
主要是参数传输的问题,我用一个label显示在DBGRID1中选中的字符,我只想传输‘001’或‘002’
但鼠标点击到英语或数学上是,显示的是英语或数学,怎么样才能只让他传输code 列的数据呢(要能同时选中多行进行查询)
001 小张
002 小强
210 王力
...........
是经过查询后在dbgrid1中显示的内容
code a1(课程) a2(成绩)
001 英语 65
001 数学 30
210 英语 56
210 数学 50
...............
这是数据库中另外一张表。
通过点击DBGRIDE1中的两行,
我现在想在DBGRIDE2中显示
001 英语 65
001 数学 30
小计 95
210 英语 56
210 数学 50
小计 106
合计 201怎么做呢,上面几位大哥好象没有明白我的意思
高手请指教
query1.sql.add(
'select code, a1, a2 from table2 where code='''+Acode[1]+''''+
'union all select code='小计', a1=' ', sum(a2) from table2 where code='''+Acode[1]+''''+
'union all select code, a1, a2 from table2 where code='''+Acode[2]+''''+
'union all select code='小计', a1=' ', sum(a2) from table2 where code='''+Acode[2]+''''+
'union all select code='合计', a1=' ', sum(a2) from table2 where code='''+Acode[1]+''' or code='''+Acode[2]+'''');
var
sqls, totals: string;
i: integer;
begin
sqls:='';
totals:='';
for i:=Low(Acode) to High(Acode) do
begin
sqls:=sqls+'select code, a1, a2 from table2 where code='''+Acode[i]+''''+
' union all '
'select code=''小计'', a1='' '', sum(a2) from table2 where code='''+Acode[i]+'''';
totals:=totals+' or code='''+Acode[i]+''''
end;
if length(trim(sqls))<>0 then
begin
totals=copy(totals, 4, length(totals));
sqls:=sqls+' union all select code='合计', a1=' ', sum(a2) from table2 where '+totals;
query1.close;
query1.sql.clear;
query1.sql.add(sqls);
query1.open;
end;