Solved

Looking to Insert Text File into DB Table with extra columns

Posted on 2003-10-22
6
730 Views
Last Modified: 2013-12-24
Hello,

I won't bother posting my lame attempts at solving this, it will probably just slow things down.  

Its just a regular tab-delimited text file - it looks basically like this:

MODEL    UPC    ISBN
A15    111111    233333
B37    234556    234233

etc.

And the table (currently in Access 2000, moving to SQL 2000 before it goes live probably) has extra columns b/c some text files will have more or less columns.  So its something like:

MODEL   MANUFACTURER   UPC   ISBN   PRICE  (etc)

What I'm trying to do is take the text file and insert all the records into the table, with the fields of course matching up.  What is the best way to do this?  The text files will be replaced on a regular basis, and so I don't want to set it up as a datasource if that's an option.

Thanks,
John
0
Comment
Question by:FogLlama
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Accepted Solution

by:
kjuliff earned 75 total points
ID: 9599474
Just read in the file into a variable using CFFILE.   You can then parse the contents of the variable by searching for the delimiters and Line Feeds.

The outer loop will process each line.
The inner loop will process each field, putting values into variables corresponding to the column names.
At the end of the loop, do an insert.
0
 
LVL 17

Assisted Solution

by:anandkp
anandkp earned 50 total points
ID: 9601008
text.txt
M, 25, akp
F, 20, aish

code:
<cfset targetfile = "#GetDirectoryFromPath(CGI.Path_Translated)#text.txt">

<cfoutput>
  <cffile action="READ" file = "#targetfile#" variable="testVar">
  <cfloop index="rc" list="#testVar#" delimiters="#Chr(10)#">
  <cfset myRecord = listtoarray(rc,",")>
 
  <cfloop index="i" from="1" to="#arraylen(myRecord)#">
     <cfset family = #myRecord[1]#>
      <cfset category = #myRecord[2]#>
      <cfset prod = #myRecord[3]#>
      #myrecord[i]#
     
   </cfloop>      
   <br>
  </cfloop>
</cfoutput>

K'Rgds
Anand
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 9605893
Will your rows have fillers if there is no data.

for ex

MODEL-3425,PRODUCT, UPCNUM,,500.00

so ISBN is blank here since it has a UPC.  would that be the format?

CJ
0
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 

Author Comment

by:FogLlama
ID: 9606824
kjuliff & anandkp,

Great stuff, thanks.

CJ,

No, no fillers for empty data.


I think I am close to a solution, I'll add another comment if I don't have any luck, but so far making some progress.

Thanks,
John
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 9606844
If there are no fillers how do you know what value corresponds to what column?

CJ
0
 

Author Comment

by:FogLlama
ID: 9609359
everyone,

OK, its working now just great.  thanks for helping!

John
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question