EntryDM.ADOQR_quality_s_add_apply_check.Close ;
    EntryDM.ADOQR_quality_s_add_apply_check.SQL.Clear ;
    EntryDM.ADOQR_quality_s_add_apply_check.SQL.add('select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp ');
    EntryDM.ADOQR_quality_s_add_apply_check.SQL.Append('from quality_s_add_apply_check where project_inspect_id=:str1 and cycle_number=:str2' );
    EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str1').Value := gl_project_inspect_id;
    EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str2').Value :=1;
    EntryDM.ADOQR_quality_s_add_apply_check.ExecSQL ;
    EntryDM.ADOQR_quality_s_add_apply_check.SQL.Clear;
    EntryDM.ADOQR_quality_s_add_apply_check.SQL.Add('select * from #quality_s_add_apply_check_temp');//发现不存在刚才建的临时表
    EntryDM.ADOQR_quality_s_add_apply_check.Open ;
我在execsql之前用了两个参数,到注释那一句就出错,说是没有刚才建的临时表
是不是execsql之前的SQL语句不能带参数?
如果不用参数,一切都ok,
如果能带,怎样带呢?

解决方案 »

  1.   


    strSQL:='select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp 
    from quality_s_add_apply_check where project_inspect_id=:str1 and cycle_number=:str2 
    select * from #quality_s_add_apply_check_temp'EntryDM.ADOQR_quality_s_add_apply_check.sql.clear;
    EntryDM.ADOQR_quality_s_add_apply_check.sql.text:=strSQL;  EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str1').Value := gl_project_inspect_id;
        EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str2').Value :=1;EntryDM.ADOQR_quality_s_add_apply_check.ExecSQL ;
      

  2.   

    不行的话,你就不要用参数形式,直接把值写到strSQL中去
    就可以了
      

  3.   

    try
    AdoQuery.SQL.add('select * from t1 where id='''+str1+'''');
      

  4.   

    阿凯,你的说法不行,我主要是想在创建一个临时表的时候,对被取记录的表先进行过滤,所以要用到两个参数,否则的话,被复制的数据可能过多。
    再有,问题不在于我后面怎样处从临时表中读数,而在于如果用到参数,临时表根本就不会建立,而且不报错,但我在执行后查看查询分析器时,里面根本不会有刚才想要创建的临时表。我会试试Debugxp的方法,他的也许行
      

  5.   

    ExecSQL
    完全可以用参数
    肯定是别的原因
      

  6.   

    同意楼上的说法,可以带参数,没有读你的sql,太乱了。肯定是别的原因造成的。
      

  7.   

    带参数没问题,但是,临时标,在你执行完ExecSQL时,已经删除,修改如下:
    +
    EntryDM.ADOQR_quality_s_add_apply_check.Close ;
        EntryDM.ADOQR_quality_s_add_apply_check.SQL.Clear ;
        EntryDM.ADOQR_quality_s_add_apply_check.SQL.add('select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp ');
        EntryDM.ADOQR_quality_s_add_apply_check.SQL.Append('from quality_s_add_apply_check where project_inspect_id=:str1 and cycle_number=:str2' );
        EntryDM.ADOQR_quality_s_add_apply_check.SQL.Add('select * from #quality_s_add_apply_check_temp');//发现不存在刚才建的临时表
        EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str1').Value := gl_project_inspect_id;
        EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str2').Value :=1;
        EntryDM.ADOQR_quality_s_add_apply_check.Open ;好了,这样就可以得到临时表中的数据了。
      

  8.   

    可以所换成一个SQL语句字符串试试,应该没有问题。
    EntryDM.ADOQR_quality_s_add_apply_check.SQL.add('select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp from quality_s_add_apply_check where project_inspect_id='+QuotedStr(gl_project_inspect_id)+' and cycle_number='
    +QuotedStr(1));
      

  9.   

    不必非用临时表不可,你要复制数据表临时用一下。
    可用TADODataSet组件,他有一个克隆的功能。
    可以复制数据集从另一个TADODataSet组件,而且速度很快。
    你在克隆的数据集进行操作不会影响到真正的数据库。
      

  10.   

    关注主题,
    同时:
    楼上说的ADS的这个COPY功能怎么设置?
      

  11.   

    execsql之前的SQL语句是肯定能带参数的,这不用怀疑!你的问题不是参数带来的,还是把注意力放在检查其他问题方面吧
      

  12.   

    用存储过程返回结果集也行,效率要好些
    create proc P_test(@s1 varchar(20),@s2 int)
    as
    begin
      select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into  #quality_s_add_apply_check_temp
      from quality_s_add_apply_check where project_inspect_id=@s1 and cycle_number=@S2 
      select * from #quality_s_add_apply_check_temp
      return 0
    end//delphi
    //dbgrid的数据源联上ADOStoredProc1 
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with ADOStoredProc1 do
      try
        Close;
        ProcedureName:='P_test;1';
        Parameters.Refresh;
        Parameters.ParamByName('@s1').Value:=gl_project_inspect_id;
        Parameters.ParamByName('@s2').Value:=1;
        Open;//返回数据集
        if Parameters.ParamByName('@return_value').Value<> then Abort;
      except
        showmessage('error');
        raise;
      end;
    end;
    调用
      

  13.   

    另外adoquery中创建的临时表不会自动释放必须调用drop table #tprocedure TForm1.Button1Click(Sender: TObject);
    begin
    with adoquery1 do
    begin
      close;
      sql.clear;
      sql.Add(' select identity(int,1,1) as id ,字段 into #t1 from 表');
      ExecSQL;
      close;
      sql.clear;
      sql.Add('select * from #t1');
      open;
    end;
    end;如果连续点俩次会报错#t已经存在
    但是存储过程会自动释放临时表不用管