请问如何才得到存储过程执行结果?存储过程:
CREATE PROCEDURE hj01
AS
begin tran
delete temphj01
insert into temphj01 select a  from temp group by aif @@error<>0 goto procommit transactionreturn 0
pro:
rollback transaction
return 1
GO调用方法1a:
  with ADOQuery2 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('exec hj01');
      Open;
    end;调用方法1b:
  with ADOQuery2 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('exec hj01');
      Open;
      s:= ADOQuery2.Fields[0].AsString;
    end;结果:存储过程有执行,但有错信息:CommandText does not return a result set.调用方法2:
  with ADOQuery2 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('exec hj02');
      ExecSQL;
      s:= ADOQuery2.Fields[0].AsString;
    end;结果:存储过程有执行,但有错信息:List index out of bounds(0)调用方法3:
  with ADOQuery2 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('exec hj01');
      ExecSQL;
    end;
结果:没有出错信息,存储过程正常执行,没有出错信息,但不知什么时候完成

解决方案 »

  1.   

    1a,1b:exec 一个不是返回数据集的存储过程,需要用execsql,跟Query一样的方式.2:方法不对.取存储过程的返回值,不要用Query.非要用的话,存储过程中的return 1,改成select 1的方式返回.3:execsql;这句代码执行完。存储过程也就执行完成了.
      

  2.   

    前提:return 1,改成select 1
    1a,1b就都可以了;
    2要在execsql后面加上active:=True; 加上后也是可以的,这里的 SQL.Add('exec hj02');不知道是不是笔误。
      

  3.   

    2:方法不对.取存储过程的返回值,不要用Query.非要用的话,存储过程中的return 1,改成select 1的方式返回.
    如果要用 QUERY 调用,把:
    CREATE PROCEDURE hj01
    AS
    begin tran
    delete temphj01
    insert into temphj01 select a  from temp group by a
    if @@error<>0 goto pro
    commit transaction
    return 0
    pro:
    rollback transaction
    return 1
    GO改成:
    CREATE PROCEDURE hj01
    AS
    begin tran
    delete temphj01
    insert into temphj01 select a  from temp group by a
    if @@error<>0 goto pro
    commit transaction
    select 0
    pro:
    rollback transaction
    select 1
    GO
    ?
    3:execsql;这句代码执行完。存储过程也就执行完成了.
    你是意思是要存储过程执行完,程序才会运行后面的代码吗?