十年

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
        今天寫程序時遇到以下問題,百思不得其解。此問題有關於sql子查詢程序,代碼如下:

with dm.qyTemp do
begin
    close;
    
with SQL do
    begin
      Clear;
      Add(
'update table set sub_total=(select sum(quantity*unit_price) as sub_total from table2 where pokey=table.rkey),Status=8 ');
      Add('where rkey=:po_key');
    end;
    Parameters.ParamByName(
'po_key').Value := inttostr(po_key);
    ExecSQL;
end;

執行後彈出如下錯誤信息:
  無法從含Sub-select的sql陳述式繼承參數資訊。准備指令之前請設定參數資訊。

        但事實上此sql語句在sql查詢分析器中即可以執行成功。
        思考良久,後來將程序改為如下就可以了:

      Add(
'update table set sub_total=(select sum(quan_ord*unit_price) as sub_total from table2 where pokey=table.rkey),Status=8 ');
      Add(' (where rkey='+inttostr(po_key)+')');
      ExecSQL;
   ...

        雖然問題得到解決,但為何會產生此問題即仍然沒有答案,難道,這會是delphi的一個bug?

posted on 2005-01-11 18:25  留不住的时光  阅读(1212)  评论(1编辑  收藏  举报