请问位高手:
  如何将用SQL语句查出来的数据,直接导成文本文件。
请问使用SQL语句能实现吗?

解决方案 »

  1.   

    可以。sqlserver是‘out’什么语法吧,记不清了,你查一下
    不同的DBMS写法不同的
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Myfile:textfile;
      i:integer;
      s:string;
    begin
      assignfile(Myfile,'out.txt');
      reset(Myfile);
      query1.First;
      while not query1.Eof do
      begin
        for i:=0 to DBGrid1.Columns.Count-1 do
        begin
          s:=DBGrid1.Columns[i].Field.Text;
          Append(Myfile);
          writeln(Myfile,s);
        end;
        query1.Next;
      end;
    end;
    在程序的文件夹里建立个空的文本文档。在form上放一个query,datesourse,dbgrid,buttonquery的SQL里面写入你的表,运行一下! 我试了! 没问题!
      

  3.   

    呵呵,楼主问的是用SQL语句实现
      

  4.   

    看看,去查一下SQL Server的联机帮助。
      

  5.   

    查一下SQL Server的联机帮助。
      

  6.   

    将SQLServer导入到文本文件
    ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp;Extended Properties="text;HDR=YES;";Persist Security Info=False'
    ADOConnection.Connected := True;
    ADOConnection.Execute('SELECT * into aaa.txt  FROM Tab1 IN [ODBC]
    [ODBC;Driver=SQL Server;UID=sa;PWD=;Server=127.0.0.1;DataBase=test;]');
      

  7.   

    你用的什么数据库,SQLSERVER可以用BCP。
      

  8.   

    不好意思,偶记错了 ‘out’是用bcp导的
    Data can be bulk copied to or from a view. This includes copying data from multiple joined tables, adding a WHERE clause, or performing special formatting such as changing data formats using the CONVERT function. For example, to bulk copy data from the view titleview in the pubs database to the Titleview.txt data file, execute at the command prompt:bcp pubs..titleview out titleview.txt -c -Sservername -Usa -Ppassword  To bulk copy data into a view using bcp or the BULK INSERT statement, the rules for inserting data into a view apply.
    -------------
    sql语句怎么实现偶也不知道