• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need help catching duplicates from csv import

Explorer ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

I have a page where a user can import a csv file. I want to check for duplicates and either disregard them and only use the number once or delete the duplicates. Here is my code:

<cffile action="read" file="#form.FiletoUpload#" variable="csvfile">
<cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#">


<cfquery name="massimport1" datasource="#bads#">
INSERT INTO table1(ID, RID, Level, Schedule, Date1,Date2)
VALUES ('#listgetAt('#index#',1, ',')#', '#id#', '#form.Level#', '#form.Schedule#', '#form.date1#', '#form.date2#')
</cfquery>

</cfloop>

Is there any way to eliminate duplicate ID numbers entered at that step? Any ideas would be appreciated.
TOPICS
Advanced techniques

Views

397

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

You could import to a temporary table, then do a SELECT DISTINCT on the fields that you are checking for dups before doing your insert.

That's what I do, anyway.

- Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

I forgot to mention - don't forget that impacts the rights they need in the datasource definition!

- Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

use this type of insert query

insert into mytable
(fields)
select distinct values
from SomeSmallTable
where
(select count(*)
from mytable
where somefield = somevalue) = 0

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 09, 2007 Feb 09, 2007

Copy link to clipboard

Copied

LATEST
Thank you guys. This works great!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation