一个ADOQuery,怎样执行几条SQL语句(50)

  • 主题发起人 leon2008go
  • 开始时间
L

leon2008go

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个Button的事件如下: adoquery1.Close ; adoquery1.SQL.Clear ; adoquery1.SQL.Add('if not object_id(''tb1'') is null drop table tb1'); adoquery1.ExecSQL ; adoquery1.Close ; adoquery1.SQL.Clear ; adoquery1.SQL.Add('Create table tb1([TrnspName] nvarchar(3),[U_bumen] nvarchar(3),[LineTotal] int)'); adoquery1.ExecSQL ; adoquery1.Close ; adoquery1.SQL.Clear ; adoquery1.SQL.Add(adoquery3.SQL.Text); adoquery1.ExecSQL ; adoquery1.Close ; adoquery1.SQL.Clear ; adoquery1.SQL.Add('select tb1.*,百分比=cast(cast(1.0*LineTotal /(select sum(LineTotal )from tb1)*100 as dec(6,2)) as varchar)+''%'' from tb1') ; adoquery1.Open ;其中adoquery3.SQL.Text的语句如下:Insert tb1 select #a.TrnspName,#a.U_bumen,sum(#a.LineTotal) as LineTotal from (select a.TrnspName,d.U_bumen,sum(b.LineTotal) as LineTotal from OSHP a join OITM c on a.TrnspCode=c.ShipTypejoin INV1 b on b.ItemCode=c.ItemCode join OINV d on b.DocEntry=d.DocEntry--where d.DocDate between :bd and :ed group by a.TrnspName,d.U_bumenwhere d.DocDate between '2009-1-1' and '2009-2-28' group by a.TrnspName,d.U_bumenunion allselect a1.TrnspName,d1.U_bumen,sum(-b1.LineTotal) as LineTotal from OSHP a1 join OITM c1 on a1.TrnspCode=c1.ShipTypejoin RIN1 b1 on b1.ItemCode=c1.ItemCode join ORIN d1 on b1.DocEntry=d1.DocEntry--where d1.DocDate between :bd and :ed group by a1.TrnspName,d1.U_bumen ) #awhere d1.DocDate between '2009-1-1' and '2009-2-28' group by a1.TrnspName,d1.U_bumen ) #agroup by #a.TrnspName,#a.U_bumenhaving #a.TrnspName<>'赠品材料' and #a.U_bumen='商场部'adoquery3.SQL.Text的语句是没错的,但是单击这个事件执行后出错,错误为:不正常地定义参数对象,提供了不一致或不完整的信息.请问哪里错了?
 
adoquery3.SQL.Text是否被清除了呢。。。
 
adoquery3.SQL.Text没被清除的
 
你这样好象太复杂了 可以 adoquery1.sql.clear; adoquery1.sql.add('');adoquery1.sql.add('');adoquery1.sql.add('');adoquery1.sql.add('');adoquery1.ExecSQL ; 这样就可以了
 
如果是adoquery1.sql.clear;adoquery1.sql.add('select * from table');adoquery1.sql.add(' where id=1');adoquery1.ExecSQL ;这样是没问题,但是我执行的是几段不同性质的SQL,第一段是创建表或者清空表,第二段是插入数据,第三段是查询数据.所以你的方法是不行的!
 
//第一语句with adoquery1 dobeginadoquery1.close;adoquery1.sql.clear;adoquery1.sql.add('第一条SQL');adoquery1.execsql;end;//第二语句with adoquery1 dobeginadoquery1.close;adoquery1.sql.clear;adoquery1.sql.add('第二条SQL');adoquery1.execsql;end;..........
 
with adoquery1 dobegin close; sql.clear; sql.add('第一条SQL'); execsql; close; sql.clear; sql.add('第二条SQL'); execsql; ....................................end;如果一句sql没有写完可多几个:sql.add('');看是否要分开写
 
你的语句中是不是主键信息(条件)不足~~
 
:bd and :ed ??参数
 
搞定了,问题出现在:1。两个时间参数,应该用两个bd和两个ed2。SQL里的注释用--符号,但放在Delphi里是出错的。谢谢大家关注!
 
接受答案了.
 
顶部