Delimiters are a set of individual characters rather than a string, so for
columnDelimiter you can simply write:

<cfset ColumnDelimiter = chr(34) & chr(44)/>

I would discard the inner loop and simply do this:

<cfloop index="index" list="#Variables.SourceFile#"
delimiters="#RecordDelimiter#">

    <cfset trackNumber = listLast(index, ColumnDelimiter)>

    <cfset headerId = listFirst(index, ColumnDelimiter)>

    <cfquery.>
</cfloop>

If your CSV is big, you mifght want to convert the records into an array
then loop over that to improve performance.



  _____  

From: Ciliotta, Mario [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 14 September 2004 9:36 a.m.
To: CF-Talk
Subject: Question about processing a CSV file.

Hi,

I was wondering if anyone could help me out as I am stuck on this part.  I
have a csv file that I would like to read and then issue an update query
based
on the contents.

Basically I would like to read the file and then loop over the file and
issue
and update query for each line (maybe I could convert it to stored procedure
later).

The file looks like this:

"5388120","12345678IL"
"5388150","FDX123FD45"
"5388165","FFFFRT6789"
"5388198","12345HY890"
"5388204","123SEDFRT"
"5388205","1ASEFFBH6"
"5388209","12890HFS23"
"5388212","124300HGFS"
"5388231","123567UHJK"
"5388235","12WWE4DD45"
"5388281","1234RFGT76"
"5388284","313SFFS67"
"5388361","23DS455555"
"5388366","4422442242"
"5388372","42242FDFSF"
"5388403","FDXUPSDELD"
"5388409","1234567890"
"5388414","ASWDERF455"
"5388415","123EDCVBH6"
"5388417","12WSED56YH"
"5388424","12WSC56HBN"
"5388428","123WSE456H"
"5388510","313DADDADA"
"5388511","HFH678947S"
"5388597","3131ADADAD"
"5388654","ADA5DFA5RD"
"5388655","AD4242DDAA"
"5388661","1331XSSA4D"

And what I want to do is loop over it and issue an update:
PUSEDOCODE:

<CFLOOP over the file>
    update table
        set track_nbr = '2345678il'
    where header_id = 5388120
</cfloop>

What is the best way to do this.  I can process the file but I am lost as to
what to do.

This is what I have so far:

<cfset RecordDelimiter = Chr(10) & Chr(13) />
<cfset ColumnDelimiter = chr(34) & chr(44)& chr(34) />

<cffile action = "" file = "G:\inetpub\wwwroot\mario\fedex_input.csv"
variable = "Variables.SourceFile">

<cfloop index="index" list="#Variables.SourceFile#"
delimiters="#RecordDelimiter#">
   <cfloop index="recordIndex" list="#index#"
delimiters="#ColumnDelimiter#">
     <cfoutput#RecordIndex#<br>
   </cfloop>
   <hr>
  </cfloop>

Thanks
Mario

  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to