Monday, March 26, 2012

MS SQL server Insert Error [109]

Greetings!

When I run the following SQL statement in Perl, I get an error
stating:
any help/pointers how this can be resolved?

Thanks,
-Murali

SQL note_insert error: [109] [2] [0] "[Microsoft][ODBC SQL Server
Driver][SQL Server]There are more columns in the INSERT statement than
values specified in the VALUES clause. The number of values in the
VALUES clause must match the number of columns specified in the INSERT
statement."

The perl code:

$sql_stmt1 = "select cast(newid () as varbinary(16)) as notes_id
from cc_test";

if($db_ends->Sql($sql_stmt1))
{
$db_ends->Error();
exit(-1);
}

while($db_ends->FetchRow())
{
undef %Data;
%Data = $db_ends->DataHash();
$notes_id = $Data{"notes_id"};
}

# Prepare the columns for insert

my$updated_detail = "$pn . $cc_ver\n";

my $note_columns = "user_note_id, bio_name, related_tbl_name,
related_string_id, related_int_id, note_type_lkp, notes,
internal_flag, revision_number, obsolete_flag";

my $note_values = "cast(" +$notes_Id + "as binary(16)), Null, Null,
Null, $bfn, 0x74942E5A0A04022800415DE63529D4B7, $notes_detail, 0, 0,
0";

$sql_note_insert = "insert into user_note ($note_columns) values
($note_values)";

if($db_ends->Sql($sql_note_insert))Make sure you delimit all strings with single quotes ('). If one of the
current variables (such as $note_details) contains a comma, then you
will have more "values" than "columns".

If this doesn't work, then please post the actual query you are
submitting to SQL-Server.

Hope this helps,
Gert-Jan

Murali Kanaga wrote:
> Greetings!
> When I run the following SQL statement in Perl, I get an error
> stating:
> any help/pointers how this can be resolved?
> Thanks,
> -Murali
> SQL note_insert error: [109] [2] [0] "[Microsoft][ODBC SQL Server
> Driver][SQL Server]There are more columns in the INSERT statement than
> values specified in the VALUES clause. The number of values in the
> VALUES clause must match the number of columns specified in the INSERT
> statement."
> The perl code:
> $sql_stmt1 = "select cast(newid () as varbinary(16)) as notes_id
> from cc_test";
> if($db_ends->Sql($sql_stmt1))
> {
> $db_ends->Error();
> exit(-1);
> }
> while($db_ends->FetchRow())
> {
> undef %Data;
> %Data = $db_ends->DataHash();
> $notes_id = $Data{"notes_id"};
> }
> # Prepare the columns for insert
> my $updated_detail = "$pn . $cc_ver\n";
> my $note_columns = "user_note_id, bio_name, related_tbl_name,
> related_string_id, related_int_id, note_type_lkp, notes,
> internal_flag, revision_number, obsolete_flag";
> my $note_values = "cast(" +$notes_Id + "as binary(16)), Null, Null,
> Null, $bfn, 0x74942E5A0A04022800415DE63529D4B7, $notes_detail, 0, 0,
> 0";
> $sql_note_insert = "insert into user_note ($note_columns) values
> ($note_values)";
> if($db_ends->Sql($sql_note_insert))sql

No comments:

Post a Comment