try to look at the this url too
http://www.bennadel.com/bl
Main Topics
Browse All TopicsI'm having a lot of problems trying to import a CSV file. There are a different number of columns for different rows. Also some of the rows include comments typed in by users in an input field and they typed in line breaks so this is causing problems. There are no problems importing this into Access using doCmd.transfertext but I need to be able to do all of this from Coldfusion. An example of the CSV file is below.
Example of CSV file.
1,"abc1","abc2","abc3","ab
1,"abc1a","abc2a","abc3a",
1,"abc1b","abc2b","abc3b",
2,"abc1","abc2","abc3","ab
2,"abc1a","abc2a","abc3a",
2,"abc1b","abc2b","abc3b",
3,"abc1","abc2","abc3","ab
3,"abc1a","abc2a","abc3a",
3,"abc1b","abc2b","abc3b",
4,"abc1","This is a comment with a line break in it.","abc3","abc4","abc5",
4,"abc1a","This is another comment with several line breaks in it.","abc3a","abc4a","abc5
4,"abc1b","abc2b","abc3b",
I could really use some help on importing this file into my SQL Server 2005 Database.
Thanks,
Tim
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
try to look at the this url too
http://www.bennadel.com/bl
Neither of those solutions worked. The biggest problem is the line breaks typed in by the users. Once any solution that I've seen hits those it forces a new row to be created where there shouldn't be one. Also I don't have access to create any new data sources so the solution in the first link wouldn't work for me. Any other suggestions?
before you rund any normal solution you need to remove line breaks within quotes like this:
<cfset withinquotes = 0>
<cfloop from="1" to="#len(csv)#" index="i">
<cfif mid(csv,i,1) eq """">
<cfif withinquotes>
<cfset withinquotes = 0>
<cfelse>
<cfset withinquotes = 1>
</cfif>
<cfelseif (mid(csv,i,1) eq chr(13) or mid(csv,i,1) eq chr(10)) and withinquotes>
<cfset csv = RemoveChars(csv, i, 1)>
<cfset csv = insert(" ",csv,1)>
</cfif>
</cfloop>
now your CSV variable will have all the line breaks within the quotes replaced with spaces so you can use the normal methods of converting the lines into an array.
I would suggest you change all the commas that are delimiters to pipes "|" and then use that as your delimiter when parsing out the fields instead of commas. Pipe delimiting is often the better to use than comma delimiting for this very reason.
<cfset withinquotes = 0>
<cfloop from="1" to="#len(csv)#" index="i">
<cfif mid(csv,i,1) eq """">
<cfif withinquotes>
<cfset withinquotes = 0>
<cfelse>
<cfset withinquotes = 1>
</cfif>
<cfelseif (mid(csv,i,1) eq chr(13) or mid(csv,i,1) eq chr(10)) and withinquotes>
<cfset csv = RemoveChars(csv, i, 1)>
<cfset csv = insert(" ",csv,1)>
<cfelseif mid(csv,i,1) eq "," and not withinquotes>
<cfset csv = RemoveChars(csv, i, 1)>
<cfset csv = insert("|",csv,1)>
</cfif>
</cfloop>
Sorry I haven't gotten back faster. I had some other issues come up that had to be taken care of. I have messed around with this for a while now and I don't think this solution will work either now. It's just taking way to long to process the files. Anywhere from 15-30 minutes a file. Any other suggestion on ways I can import this file?
Business Accounts
Answer for Membership
by: srikanthmadishettiPosted on 2007-09-18 at 08:12:58ID: 19913596
look at the following url
com/index. cfm/2007/2 /5/csv
http://www.coldfusionmuse.
hope it helps