Re: Export data to CSV in SQL Server



On Mon, 01 Mar 2010 19:36:06 -0500, Arne Vajhøj wrote:

On 01-03-2010 17:07, Martin Gregorie wrote:
On Mon, 01 Mar 2010 13:18:01 -0800, olegkon wrote:
I am trying to write a Java JDBC program exporting data from the
database into CSV file using SQL Server 2005 DB.

From that query:
String="SELECT * into OUTFILE '"+filename+'" FIELDS TERMINATED BY ','
FROM table1";
getting: "SQLException: Incorrect syntax near 'myfilename.csv'

Yes, I put filename in single quotes. Same problem without them, but
it strips out csv file extension.

Obvious: your single and double quotes are mismatched.

Use '"+filename+"' instead of '"+filename+'"

I don't think he would get an SQLException if his code really had that
problem.

I'm surprised the OP's code even compiled unless '"+filename+'" was a
typo. My rearrangement would at least compile correctly. I don't know SQL
Server well enough to know whether it would like the 'into outfile'
syntax. Postgres doesn't.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
.



Relevant Pages

  • Export data to CSV in SQL Server
    ... I am trying to write a Java JDBC program exporting data ... from the database into CSV file using SQL Server 2005 DB. ... getting: "SQLException: Incorrect syntax near 'myfilename.csv' ... Is there a better way of doing it in SQL server? ...
    (comp.lang.java.databases)
  • Re: Export data to CSV in SQL Server
    ... database into CSV file using SQL Server 2005 DB. ... FROM table1"; ... getting: "SQLException: Incorrect syntax near 'myfilename.csv' ...
    (comp.lang.java.databases)
  • Re: Export data to CSV in SQL Server
    ... database into CSV file using SQL Server 2005 DB. ... FROM table1"; ... getting: "SQLException: Incorrect syntax near 'myfilename.csv' ...
    (comp.lang.java.databases)
  • Incorrect syntax near keyword ON ????
    ... i was trying to create a DB in a SQL Server. ... It gave me this SQLexception "Incorrect syntax near keyword 'ON" ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Export data to CSV in SQL Server
    ... from the database into CSV file using SQL Server 2005 DB. ... getting: "SQLException: Incorrect syntax near 'myfilename.csv' ...
    (comp.lang.java.databases)