delphi adoquery 子查询
时间:2011-11-26
来源:互联网
菜鸟问题,我在adoquery 里用了子查询 select ... from ... where (字段1)= ... and (字段2) in (select .. from .. where ...) group by ...
数据库为access,两个表在同一个数据库里,代码如下:
sql_str:= 'SELECT tf_grade as 等级, count(tf_batchid) AS 数量,count(tf_batchid)*100/:S0 AS 百分比 ';
sql_str:=sql_str + 'FROM after_gradedata WHERE (tf_batchid=:S1) and (tf_trayid in ';
sql_str:=sql_str + '(select tf_trayid from tray_index where tf_batchid =:S2 ))';
adoquery6.SQL.Add(sql_str);
adoquery6.SQL.Add('group by tf_grade');
showmessage(adoquery6.SQL.Text );
adoquery6.Parameters [0].Value :=strtoint(Labelcellcount.Caption);
adoquery6.Parameters [1].Value :=trim(edit2.Text );
adoquery6.Parameters [2].Value :=trim(edit2.Text );
adoquery6.Active :=true;
adoquery6.Open ;
在access 里是可以查到的,可在delphi 里,结果却什么都没有,不知哪里有错.
数据库为access,两个表在同一个数据库里,代码如下:
sql_str:= 'SELECT tf_grade as 等级, count(tf_batchid) AS 数量,count(tf_batchid)*100/:S0 AS 百分比 ';
sql_str:=sql_str + 'FROM after_gradedata WHERE (tf_batchid=:S1) and (tf_trayid in ';
sql_str:=sql_str + '(select tf_trayid from tray_index where tf_batchid =:S2 ))';
adoquery6.SQL.Add(sql_str);
adoquery6.SQL.Add('group by tf_grade');
showmessage(adoquery6.SQL.Text );
adoquery6.Parameters [0].Value :=strtoint(Labelcellcount.Caption);
adoquery6.Parameters [1].Value :=trim(edit2.Text );
adoquery6.Parameters [2].Value :=trim(edit2.Text );
adoquery6.Active :=true;
adoquery6.Open ;
在access 里是可以查到的,可在delphi 里,结果却什么都没有,不知哪里有错.
作者: yanfl102 发布时间: 2011-11-26
如果你的字段是字符型,那么 QuotedStr(edit2.Text)
作者: bdmh 发布时间: 2011-11-26
我的是字符型,我另一段代码和这段差不多,另一段没有用 in ,也是用trim ,可以正常查询
作者: yanfl102 发布时间: 2011-11-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28