in reply to Re: CONCAT Perl or SQL
in thread CONCAT Perl or SQL

I have tried several variations on a theme including:

my $sthG = $dbh->prepare("INSERT into ICD_9_Disease_Types (ICD_9_code) + SELECT CONCAT('A', select ICD_9 from ICD_9 where ICD_9 > 0);") or di +e "Couldn't prepare query: ".$dbh->errstr;

I am transferring between two different tables.

Replies are listed 'Best First'.
Re: Re: Re: CONCAT Perl or SQL
by mpeppler (Vicar) on Dec 03, 2003 at 17:20 UTC
    Please go read the Transact-SQL manual.

    I just showed you above that you concatenate strings in SQL using the '+' operator:  select "A" + ICD_9 ...

    You are at a point where you don't yet understand SQL - I strongly suggest that until you understand SQL you leave perl and DBI out of it, and write the queries that you want to execute in a text editor and run them using isql.exe or some other tool that connects directly to the database. This will give you direct feedback on what you are doing.

    Are you inserting a NEW row in the ICD_9_Disease_Types table, or are you updating an existing row?

    From the code above I am guessing that you are updating an existing row, in which case you need to know the relationship between the two tables.

    Michael

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re: Re: CONCAT Perl or SQL
by Itatsumaki (Friar) on Dec 03, 2003 at 15:38 UTC
    my $sql = " UPDATE ICD_9_Disease_Types SET ICD_9_code = CONCAT('A', ICD_9_code) WHERE ICD_9 > 0"; my $sth = $dbh->prepare($sql) or $dbh->errstr(); my $rows_updated = $sth->execute(); print "We updated $rows_updated rows\n";
      I don't think that CONCAT works with MS SQL Server. I have tried the following that does not give any error message but does not do what I want either.
      my $sqlB = "update ICD_9_Disease_Types set ICD_9_code = ('A') + IC +D_9 FROM ICD_9 WHERE ICD_9 > 0"; my $sthG = $dbh->prepare($sqlB) or $dbh->errstr(); my $rows_updated = $sthG->execute(); print "We updated $rows_updated rows\n";

      It gives the message:

      We updated 0E0 rows

      I am not really sure what the OEO refers to.