in reply to Inserting values in to table with DBI

Can't you do it entirely database-side? Or do you literally need to have the "A" be something else for each entry?

In standard SQL, this is either:

UPDATE disease_types SET adapted_code = "A" || code;
if you're trying to modify the records in place, or if you really wanna create a whole new set of records, more like:
INSERT INTO disease_types (adapted_code) SELECT "A" || code FROM disease_types;

You can execute either of these with a $dbh->do(...) operation.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Inserting values in to table with DBI
by Win (Novice) on Dec 08, 2003 at 13:59 UTC
    The MS SQL Standard
    my $sthH = $dbh->prepare("INSERT INTO Disease_types (Adapted_code) SELECT ('A'+code) FROM Disease_types") or die "Couldn't prepare query: + ".$dbh->errstr; $sthH->execute() or die "Couldn't execute query: ".$sthH->errstr;
    gives....
    DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver][SQL +Server]Str ing or binary data would be truncated. (SQL-22001) [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been +terminated . (SQL-01000)(DBD: st_execute/SQLExecute err=-1) at Creating_table.pl +line 389 .

    I know that I need to read up on SQL .... but when the Microsoft page:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlr +ef/ts_operator_3qov.asp
    .... tells me this, I just stuck.