declare  @begindate datetime
select @begindate=getdate()
select top 1000 * from tabel a,tabel b where a.xxx=b.xx
select time1=isnull(datediff(ss,@begindate,getdate()),0)在DELPHI中我一次执行这样几条语句,如何在程序里取time1的列值呢?我主要是想取得一条那条SQL语句的执行时间

解决方案 »

  1.   

    写成存储过程,create proc myproc
    as
    declare  @begindate datetime
    select @begindate=getdate()
    select top 1000 * from tabel a,tabel b where a.xxx=b.xx
    select time1=isnull(datediff(ss,@begindate,getdate()),0)在delphi中调用存储过程 with adoquery1 do
      begin
        close;
        sql.clear;
        sql.add('exec myproc');
        open; 
      end;
     showmessage(floattostr(adoquery1.FieldValues['time1']))
      

  2.   

    那你把存儲過程改為這樣create proc myproc 
    @sql  varchar(1000)='select top 1000 * from tabel a,tabel b where a.xxx=b.xx';
    as 
    begin
    declare  @begindate datetime 
    select @begindate=getdate() 
    exec (@sql)
    select time1=isnull(datediff(ss,@begindate,getdate()),0)
    end
     
    你調用這個存儲過程可以向下面這樣調用
    exec myproc 'select top 1000 * from tabel a,tabel b where a.xxx=b.xx'
      

  3.   

    对于sql server,ADOQuery执行多个语句会返回多个数据集,你可以访问其中你想要的数据集