注册 登录
编程论坛 Delphi论坛

复合查询语句报错

青鸟初飞 发布于 2006-12-18 13:42, 576 次点击
IF ((comboBox2.text)<>'') AND ((comboBox1.text)<>'') THEN
SQL.Add('SELECT ROWNUM AS 序号,DEPT_ID AS 区域,BURE_NO AS 所属局,dev_code AS 管道段编码,P_LEN AS 管道段长度,STREET AS 道路名,P_HOLEN AS 总孔数,OPER_DATE AS 投产日期 FROM TTMP_OBJ_PM WHERE (bure_no LIKE '+''''+'%'+Trim(ComboBox2.Text)+'%'+''') AND (dept_id LIKE '+''''+'%'+Trim(ComboBox1.Text)+'%'+''')');


注:WHERE (bure_no LIKE '+''''+'%'+Trim(ComboBox2.Text)+'%'+''') AND (dept_id LIKE '+''''+'%'+Trim(ComboBox1.Text)+'%'+''')'); 中间用 and连接报错,单独查询正常
2 回复
#2
volte2006-12-19 08:49
if (Trim(ComboBox2.Text) <> '') and (Trim(ComboBox1.Text) <> '') then
begin
SQL.Add('SELECT ROWNUM AS 序号,DEPT_ID AS 区域,BURE_NO AS 所属局,dev_code AS 管道段编码,P_LEN AS 管道段长度,STREET AS 道路名,P_HOLEN AS 总孔数,OPER_DATE AS 投产日期 FROM TTMP_OBJ_PM')
SQL.Add('WHERE bure_no LIKE '''+'%'+Trim(ComboBox2.Text)+'%'+'''')
SQL.Add('AND dept_id LIKE '''+'%'+Trim(ComboBox1.Text)+'%'+'''');
end;

测试一下!
#3
nongen2006-12-19 09:51
(bure_no LIKE '+''''+'%'+Trim(ComboBox2.Text)+'%'+''') AND (dept_id LIKE '+''''+'%'+Trim(ComboBox1.Text)+'%'+''')'
不要加括号
1