Hi mRichmon,
I appriciate your input, although I don't fully understand , could you expand on it a little.
Thanks,
Jmosher44
Main Topics
Browse All TopicsHello Experts,
I am having a hard time solving this issue, the code below is used to import the data from an excel spreadsheet into a SQL DB, the code works fine, except when there is a blank cell in the spreadsheet, the ,, in the csv file is not recognised as a value and is skipped resulting in an element being undefined. an example of this is the spreadsheet has an address1 and an address2 field, all entries have an addess1 value though some entries do not have an address2 entry depending weather or not there is a unit or suite number. I have tried different things to remedy this with no success. The issue can be resolved by simply changing the csv file (value1,value2,,value4 to value1,value2, ,value4. Notice the space in the commas between value 2 and 4) but it is not preferred to leave this in the shippers hands. Any help will be appreciated
the Code
<cffile action="READ"
file="c:\temp\address.csv"
variable="csvfile">
<!--- loop through the CSV-TXT file on line breaks and insert into database --->
<cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(
<cfquery name="importcsv" datasource="#dsn#">
INSERT INTO Table (Name,Company,Address1,Add
VALUES
('#listgetAt('#index#',1, ',')#',
'#listgetAt('#index#',2, ',')#',
'#listgetAt('#index#',3, ',')#',
'#listgetAt('#index#',4, ',')#',
'#listgetAt('#index#',5, ',')#',
'#listgetAt('#index#',6, ',')#',
'#listgetAt('#index#',7, ',')#',
'#listgetAt('#index#',8)#'
)
</cfquery>
</cfloop>
<!--- use a simple database query to check the results of the import - dumping query to screen--->
<cfquery name="csvimport" dbtype="text/html" datasource="#dsn#">
SELECT * FROM table
</cfquery>
<cfdump expand="yes" var="#rscsvdemo#">
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.
Here is the simple example of putting in the space instaed of relying on the shipper to do so:
<cfset massagedcsvfile = Replace(csvfile, ",,", ", ,", "ALL")>
Then just use the new variable with the space where there was a ,, before.
Also you can remove the space by doing a Trim on the value after it is extracted.
mRichmon,
your suggestion works perfectly, although now I am having a problem with names with a ' in it like O'neil it is being dealt with as 'neil'
as is in this error
[Macromedia][SQLServer JDBC Driver][SQLServer]Line 3: Incorrect syntax near 'Neill'. I am sure I can deal with it in the same manner as you described. Any suggestions would be appriciated.
Business Accounts
Answer for Membership
by: mrichmonPosted on 2005-11-09 at 10:30:07ID: 15258671
What I would do is use Regular expressions and look for ,, and turn into either , , or ,'', (but if you use the single quotes then you should have all values in single quotes - this could be done with the list functions and adding ' around each value unless the value was '' then leave alone).