PaiMei has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks! I'm here seeking for help and guidance. The main part of my code is the following:
for my $i ($new->{'minrow'} .. $new->{'maxrow'}){ for my $j ($new->{'mincol'} .. ($new->{'maxcol'} - 1)){ $cell = $worksheetloop->get_cell($i, 0); $CodColab = $cell->value(); $cell = $worksheetloop->get_cell(1, $j); $CodTecno = $cell->value(); $cell = $worksheetloop->get_cell($i, $j); $cellVal = $cell->value(); if(!defined($cell) or $cell->value() eq ""){ $cellVal = 0; } $sqlCom = "INSERT INTO Level (Codigo, Nivel, DataAval, + CodColab, CodTecno) VALUES (?, ?, ?, ?, ?)"; $sth = $dbh->prepare($sqlCom); $sth->bind_param(1, $counter); $sth->bind_param(2, $cellVal); $sth->bind_param(3, "2014-02-04"); $sth->bind_param(4, $CodColab); $sth->bind_param(5, $CodTecno); print "$sqlCom\n"; getc(); $sth->execute(); $counter++; } }
It should Insert those values at a table called Level, but it wont insert. It says "Execute failed: Syntax error on insert into statement (SQL-42000)" I've checked the table, its fields and values, everything and it should be okay, but its not. And thats why I'm here seeking for help. Someone, please? NOTE: I found the problem. The table name is a SQL Reserved Word. Thank you!

Replies are listed 'Best First'.
Re: Perl, Excel and MS Access Database (SQL-42000)
by jellisii2 (Hermit) on Feb 04, 2014 at 12:52 UTC
    This smacks of either a problem with your db handle or the query itself. Ensure you can connect as the user you're using from the machine that's running the script (with Access I'd assume it's local, but I don't like making assumptions like that) and can do an insert on that table. Also ensure you're not missing data for columns that have no default and are set not_null.
      Thanks for your reply. I have another script that does insert data on this same database, but never to this table called Level. Yes its a local database. I checked everything you said at least 10 times. I really don't know why its happening. Oh, I found it. "Level" is a SQL reserved word. Thank you again!