kyle972
asked on
Perl CSV to Access- IF RECORD DOESNT EXIST
The code below works correctly and inserts values from the CSV file into the Access Database. How do I adjust the script to check and see if the record from the CSV file already exists in the database?
I do not want to import duplicate records. Thanks.
I do not want to import duplicate records. Thanks.
use DBI;
$fhour="00";
$count=0;
$finterval=12;
do {
$csvfile="C:/WeatherModel/degrib/bin/Model/Output/gfs_2010111900_" . $fhour. ".csv";
$dbh = DBI->connect('dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=c:/weathermodel/weathermodel.mdb', '', '');
$sth = $dbh->prepare( "INSERT INTO GFS_Forecasts VALUES (?,?,?,?,?,?)" );
open CSV, $csvfile;
$x=0;
while(<CSV>) {
if ($x>0){
chomp;
my @fields = split /,/;
$sth->execute(@fields);
}
$x++;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.