Solved

Looking to Insert Text File into DB Table with extra columns

Posted on 2003-10-22
6
725 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
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now