Since your data file is fixed, I'd go about it like this:

<cfloop index="row" list="#Variables.SourceFile#"
delimiters="#RecordDelimiter#">
  <!--- get the fields --->
  <cfset nbr = listFirst(row) />
  <cfset hid = listLast(row) />
  <!--- remove the quotes --->
  <cfset nbr = mid(nbr, 2, len(nbr) - 2) />
  <cfset hid = mid(hid, 2, len(nbr) - 2) />
  <!--- do the update --->
  <cfquery ... >
    UPDATE table SET
         track_nbr = <cfqueryparam cfsqltype="cf_sql_varchar" value="#nbr#" />
    WHERE headerID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#hid#" />
  </cfquery>
</cfloop>

That's completely untested, but it should be pretty close.

cheers,
barneyb

On Mon, 13 Sep 2004 22:36:19 +0100, Ciliotta, Mario
<[EMAIL PROTECTED]> wrote:
>
> 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"
> "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
--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to