Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select statement : COMMA DELIMITED

Status
Not open for further replies.

RemingtonSteel

Programmer
Jul 14, 2006
65
0
0
GB
Hello folks,

How can I convert a SQL statement result into a comma delimited file?

For Example:

Select * from customers into [delimited file] ?

Thanks guys!
 
Code:
Select * from customers into CURSOR crsTest
COPY TO MyCommaFile CSV
** or COPY TO MyCommaFile DELIMITED

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
 
Hello Again!
I was wondering why the COPY TO command doesn't work on Query Analyzer. Any thoughts on this?

Thanks a lot!
 
I was wondering why the COPY TO command doesn't work on Query Analyzer. Any thoughts on this?

Because copy to is a VFP command and SQL Server doesn't understand VFP.

What you need to do is to connect to SQL Server from VFP and use SQLEXEC to run your query. This will give you a local VFP cuors and you can use the COPY TO command on that,

See SQLCONNECT(), SQLSTRINGCONNECT(), and SQLEXEC() in the on-line help.

Alternatively, you can create a remote view in VFP and use the COPY TO command on that.

Marcia G. Akins
 
Or, if you prefer to work exclusively in the Query Analyzer, you could do it with bcp.

This is not tested, but it should work OK:

Code:
SELECT * INTO #TempTable FROM MyTable
BCP #TempTable out c:\data\MyTable.txt -c -t,

(Note the comma after the -t - that's the delimiter.)

But personally I'd do as Marcia suggested.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top