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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help copying to delimited file 2

Status
Not open for further replies.

spectrum42

Programmer
Nov 28, 2000
9
US

I need to copy a table to a text file with:
1) fields separated with pipes (no problem)
2) no quotes around the fields

An example of the text file I want to generate is:
John Doe|04/30/2001|New York|01234
Mary Smith|04/29/2001|Texas|76543

How can I do this? What do I put in place of the question mark below?

COPY TO file.txt delimited with ? with character '|'

 
I thought you could simply say:

Code:
COPY TO file.txt delimited with character '|'

but that doesnt seem to work. If you can live with spaces, simply replacing your ? with ' ' will give you space padded fields. But there's probably a better solution someone around here will come up with.

Dave Dardinger

 
Hi spectrum42,

FP insists that character fields be encapsulated by a specified character, in the event the delimited character is contained within the value of one of the character fields. For Instance, if you have a table MyTable with two fields, ID C(6), Comment C(50):

INSERT INTO MyTable(ID,Comment) VALUES('000010','A|B|C|D')
COPY TO MyFile.Txt DELIMITED WITH Character '|'
MODI FILE MyFile.Txt

If it werent for the encapsulating quotes, it would appear the table consisted of five columns, not two.

Here's a work-around solution to rid yourself of those persistent quotes:

Code:
lcDelim=CHR(7)
COPY TO MyFile.Txt DELIMITED WITH &lcDelim WITH CHARACT '|'
lcFile=FILETOSTR('myfile.txt')
ERASE myfile.txt
STRTOFILE(STRTRAN(lcFile,CHR(7),''),'myfile.txt')
Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top