First you will need to check if the record is already there assuming FuelCrd is the unique value in the table (cardlock)
'SELECT FuelCrd FROM cardlock WHERE FuelCrd = $FuelCrd'; if the SELECT does return a value then the record is there. In this case you will need issue an UPDATE statement 'UPDATE cardlock SET TrkID=$TrkID, FuelCmp=$FuelCmp WHERE FuelCrd = $FuelCrd'; Otherwise, use the INSERT statement you have. ----- Original Message ----- From: "Scott Taylor" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, October 31, 2002 9:34 PM Subject: SQL table updates > Hello all, > > Can anyone tell me how to make this code work, so that, if the record > already exists, just update the values instead of creating a new record? > > open(InFile, "fuelcrd") || die "Can not open file: $!\n"; > while(<InFile>){ > chomp; > my ($FuelCrd, $TrkID, $FuelCmp) = split(/,/,$_); > $FuelCrd =~ s/\"//g; > $TrkID =~ s/\"//g; > $FuelCmp =~ s/\"//g; > chomp($FuelCrd, $TrkID, $FuelCmp); > print "$FuelCrd, $TrkID, $FuelCmp\n"; > $SQL = qq[insert into cardlock (cardno, trkid, fuelcmp) > values ('$FuelCrd', '$TrkID', '$FuelCmp')]; > $sth = $dbh->prepare($SQL) || die "$SQL\n$!\n"; > $sth->execute || die "$SQL\n$!\n"; > } > close InFile; > > $sth->finish; > $dbh->disconnect; > > ---- > > My pseudo code looks like this: > > find first record in table where id = 'blah' > if not available record then create record. > assign values to record. > > Cheers. > > Scott. > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]