我用下面的代码实现查询功能:
procedure TForm1.Button1Click(Sender: TObject);
begin
Query1.close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from rskb where name=:name1');
Query1.SQL.Add("select name into :va from rskb where name = '张红'");
Query1.ParamByName('name1').Asstring:=Edit1.text;
Query1.Prepare;
Query1.Open;
end;
结果我在Grid中显示出来,现在我同时还想将结果保存到一章临时表当中,并且我要在其他Table当中要能调用这些记录,我应该怎么做呢?请各位帮忙解决!谢谢!麻烦各位赋点代码!小弟初学!麻烦了!

解决方案 »

  1.   

    select * into #tmptable from (select * from xskb where name=:name1)
      

  2.   

    不行啊,我试了提示错误:
    Project Project21.exe raiseed exception class EDbEngineError with 
    message 'General SQL error.
    [Microsoft][ODBC SQl Server Driver][SQl Server]line:Incorrect syntax near')'.',Process stoped. Use Step or Run to continue.
    代码如下:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Query1.close;
    Query1.SQL.Clear;
    Query1.SQL.Add('select * into tmptable from');
    Query1.SQL.Add('(select * from xskb where name=:name1)');
    Query1.Prepare;
    Query1.ParamByName('name1').Asstring:=Edit1.text;
    Query1.Open;
    end;
    我还在SQL中建了一张tmptable表
      

  3.   

    这样写
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Query1.close;
    Query1.SQL.Clear;
    Query1.SQL.Add('select * into tmptable from ');
    Query1.SQL.Add('(select * from xskb where name=:name1)');
    Query1.ParamByName('name1').Asstring:=Edit1.text;
    Query1.Prepare;
    Query1.Open;
    end;
    下面这句字符串最后加上一个空格
    Query1.SQL.Add('select * into tmptable from ');
      

  4.   

    看看我这段代码,实际中用的
              strSQL := 'select count(*) as cnt  into #tmpcnt' + areacode
                  + ' from app_log_transamountviewr where jy_res = ''0000''';
              if areacode<>'' then
              begin
                strSQL := strSQL + ' and areacode=''' + areacode + ''' ';
              end;
              strSQL := strSQL + ' group by op_date having op_date like ''' + ACond + '%'' ';
    //          SQL.Add(strSQL);
              SQL.Text := strSQL;          SQL.Add( 'select max(cnt) from #tmpcnt' + areacode);
              SQL.Add('drop table #tmpcnt' + areacode);