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

VARIABLE COLUMN NAMES IN CSV FILE 1

Status
Not open for further replies.

jwxpnd

Programmer
Sep 29, 2005
43
US
How do I create a CSV file with variable column names?

SELECT CUSID AS "CUSTOMER_ ID",;
UTKDESC,; <--- The value in this field I want to use as my caption for the field below it.
UTKVAL1,;
FROM trda;
INTO CURSOR Trak1a

SELECT Trak1a
COPY TO \XReports\EXPTEST.CSV FIELDS CSV


Thanks!
CJ
 
first; if I understand this correctly, you want whats in "UTKDESC" as a column name, Right?
Now how many records are there in this table? i.e. how many differnt values are there in UTKDESC and do you want a seperate column for each?
 
It sounds like you may be looking for a cross-tab. See whether VFPXTAB.PRG in the VFP home directory gives you a cursor in the form you want.

Tamar
 
Or you can build a Fieldname string (cHeaderStr) by using the AFIELDS() command and its resultant array.

Once you have the fieldname string, you can use the FILETOSTR() command, to get your CSV file into a single string (cFileStr).

Then
Code:
cNewFile = cHeaderStr + CHR(13) + CHR(10) + cFileStr
=STRTOFILE(cNewFile,<pathed file name>)

Good Luck,
JRB-Bldr
 
Yes, UTKDESC is a column/field currently. I want to do is use whatever is in that column/field as the header for UTKVAL1 when I create the CSV file.

Example Code:

SELECT CUSID AS "CUSTOMER_ ID",;
UTKVAL1 AS "Whatever was in the field UTKDESC",;
FROM trda;
INTO CURSOR Trak1a

SELECT Trak1a
COPY TO \XReports\EXPTEST.CSV FIELDS "CUSTOMER_ ID", "Whatever was in the field UTKDESC" CSV
 
SELECT CUSID AS "CUSTOMER_ ID",;
CAST(UTKVAL1 AS C(50)) as (UTKDESC) ;
FROM trda;
INTO CURSOR Trak1a

Though this will create 2 columns, customer_id and the FIRST record value in utkdesc, as the Second column, which will contain the utkval1 records

If you want more columns i.e. each record in utkdesc, you have to create the cursor in a different way
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top