H
hcx
Unregistered / Unconfirmed
GUEST, unregistred user!
请问各位大侠下面的语句出了什么问题,执行后记录没有改变.
我写的代码如下:
DDprice.DataModule1.Qprice_cust.Close;
DDprice.DataModule1.Qprice_cust.SQL.Clear;
DDprice.DataModule1.Qprice_cust.sql.add('select * from price where pricedate=date and dstid like' +''''+'A%'+''''+' order by custid');
DDprice.DataModule1.Qprice_cust.ParamByName('pdate').asstring:=currentdate;
DDprice.DataModule1.Qprice_cust.open;
DDprice.DataModule1.Qprice_cust.First;
with DDprice.DataModule1 do
begin
while not Qprice_cust.Eof do
begin
Qchkrecd.close;
Qchkrecd.sql.clear;
Qchkrecd.sql.add('select * from price where custid=:cst and goodsid=:gsd and dstid not like '+''''+'A%'+''''+' order by custid,goodsid');
Qchkrecd.parambyname('cst').asstring:=Qprice_cust.fieldbyname('custid').asstring;
Qchkrecd.parambyname('gsd').asstring:=Qprice_cust.fieldbyname('goodsid').asstring;
Qchkrecd.open;
if Qchkrecd.recordcount=0 then // 没有执行的记录;
begin
1 try
2 DDprice.StartTransaction;
3 Qupexist.Close;
4 Qupexist.SQL.Clear;
5 //UPDATE dbo_price a INNER JOIN dbo_cust AS b ON a.custid = b.custid SET a.dstid = b.dstid where a.dstid like 'A*'
6 Qupexist.SQL.add('UPDATE price SET dstid =(select distinct dstid from cust where custid=:cst) where custid=:cst and pricedate=dt and goodsid=:gsd and dstid like '+''''+'A%'+'''');
7 Qupexist.ParamByName('cst').asstring:=Qprice_cust.fieldbyname('custid').asstring;
8 Qupexist.ParamByName('pdt').asstring:=currentdate;
9 Qupexist.ParamByName('gsd').asstring:=Qprice_cust.fieldbyname('custid').asstring;
10 Qupexist.ExecSQL;
11 DDprice.Commit;
12 except
13 DDprice.Rollback;
14 // report_error_log();
15 raise;
16 end;
end
else //有执行的记录
Qprice_cust.Next;
end; end;
我原没有1,2,11,12,13,14,15,16句,后来加上效果还是一样.
(为什么第五句在access中能执行.而在delphi中不能执行.)
由于不是同一Query查询出后再改(是改由另一查询后得出的数,然后判断此记录该如何改),我没有用updatesql. 因用updatesql的语句不好写.
我写的代码如下:
DDprice.DataModule1.Qprice_cust.Close;
DDprice.DataModule1.Qprice_cust.SQL.Clear;
DDprice.DataModule1.Qprice_cust.sql.add('select * from price where pricedate=date and dstid like' +''''+'A%'+''''+' order by custid');
DDprice.DataModule1.Qprice_cust.ParamByName('pdate').asstring:=currentdate;
DDprice.DataModule1.Qprice_cust.open;
DDprice.DataModule1.Qprice_cust.First;
with DDprice.DataModule1 do
begin
while not Qprice_cust.Eof do
begin
Qchkrecd.close;
Qchkrecd.sql.clear;
Qchkrecd.sql.add('select * from price where custid=:cst and goodsid=:gsd and dstid not like '+''''+'A%'+''''+' order by custid,goodsid');
Qchkrecd.parambyname('cst').asstring:=Qprice_cust.fieldbyname('custid').asstring;
Qchkrecd.parambyname('gsd').asstring:=Qprice_cust.fieldbyname('goodsid').asstring;
Qchkrecd.open;
if Qchkrecd.recordcount=0 then // 没有执行的记录;
begin
1 try
2 DDprice.StartTransaction;
3 Qupexist.Close;
4 Qupexist.SQL.Clear;
5 //UPDATE dbo_price a INNER JOIN dbo_cust AS b ON a.custid = b.custid SET a.dstid = b.dstid where a.dstid like 'A*'
6 Qupexist.SQL.add('UPDATE price SET dstid =(select distinct dstid from cust where custid=:cst) where custid=:cst and pricedate=dt and goodsid=:gsd and dstid like '+''''+'A%'+'''');
7 Qupexist.ParamByName('cst').asstring:=Qprice_cust.fieldbyname('custid').asstring;
8 Qupexist.ParamByName('pdt').asstring:=currentdate;
9 Qupexist.ParamByName('gsd').asstring:=Qprice_cust.fieldbyname('custid').asstring;
10 Qupexist.ExecSQL;
11 DDprice.Commit;
12 except
13 DDprice.Rollback;
14 // report_error_log();
15 raise;
16 end;
end
else //有执行的记录
Qprice_cust.Next;
end; end;
我原没有1,2,11,12,13,14,15,16句,后来加上效果还是一样.
(为什么第五句在access中能执行.而在delphi中不能执行.)
由于不是同一Query查询出后再改(是改由另一查询后得出的数,然后判断此记录该如何改),我没有用updatesql. 因用updatesql的语句不好写.