進出口使用SQL Server 2005中使用Delphi 2010SQL查詢犯規完成
我有一個表ventas
與id_venta
(PK)= id_sale,total
(的銷售),(以上數值),estado
=狀態(有效/無效)和cumulative
。
該表註冊商店的所有物品的銷售,我需要註冊總行逐行的累計總和。如果一天中有多個班次,則使用狀態字段指定班次中的銷售額。即時通訊使用此查詢:
Declare @id integer;
set @id=(Select min(id_venta) from ventas where estado='activo');
while(select @id)<=(Select max(id_venta) from ventas)
begin
update ventas set acumulado=(select sum(total) from ventas
where id_venta<[email protected] and estado='activo') where [email protected]
select @[email protected]+1
end
此查詢確實exacly我想要的東西,當我在SQL運行,但是當我做它在德爾福它只是給了我大約151行的431,不整理COMULATIVE。
這是我的Delphi代碼:
conect.Q_equivalencias.Active:=false;
conect.Q_equivalencias.SQL.Clear;
conect.Q_equivalencias.SQL.Add('Declare @id integer; set @id=(Select min(id_venta) from ventas where estado='+char(39)+'activo'+char(39)+');');
conect.Q_equivalencias.SQL.Add('while(select @id)<=(Select max(id_venta) from ventas) begin');
conect.Q_equivalencias.SQL.Add('update ventas set acumulado=(select sum(total) from ventas ');
conect.Q_equivalencias.SQL.Add('where id_venta<[email protected] and estado='+char(39)+'activo'+char(39)+') where [email protected]');
conect.Q_equivalencias.SQL.Add('select @[email protected]+1 end');
conect.Q_equivalencias.ExecSQL;
我有什麼做的,所以我在Delphi查詢完成?
編輯:
奇怪的事情發生了,我試着用conect.Q_equivalencias.Open;
insted的的conect.Q_equivalencias.ExecSQL;
和ofcourse它扔我一個error creating cursor handler
但它完成了查詢,所有行進行了更新,這是爲什麼?
試了很多東西,看來我的德爾福查詢只更新152行...
您正在使用哪個數據庫組件? – RRUZ
TQuery,TDataSource,通過ODBC連接,我有更多的插入,更新,選擇查詢,但這是唯一一個給我一個問題,查詢本身做什麼必須在SQL管理Studio Express中做但在Delphi 2010中不完。 –
我見過一個類似的問題,那就是查詢花費的時間長度,如果它佔用了一定的數量,它將只是無限期地掛起。這是幾年前,我不記得我們如何解決它。 –