Solved

Looking to Insert Text File into DB Table with extra columns

Posted on 2003-10-22
6
728 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

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.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

816 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

12 Experts available now in Live!

Get 1:1 Help Now