<?xml version="1.0" encoding="windows-1252"?>
<node id="660037" title="Re: DBI place holder for sub query problem" created="2008-01-02 14:08:27" updated="2008-01-02 09:08:27">
<type id="11">
note</type>
<author id="67275">
jZed</author>
<data>
<field name="doctext">
Generally, placeholders can only hold the place of *values*, not structural elements like table and column names and subselect queries.  You can (for most DBDs, I believe) use placeholders for values in a subquery so something like this might work:

&lt;c&gt;
$sth=$dbh-&gt;prepare("
    UPDATE tableA
    SET colA =( SELECT colB FROM tableB WHERE colC=? )
    WHERE tableA.rec_no=?
");
foreach my $row ( @rows ) {
    $sth-&gt;execute(
        $row-&gt;{'tableB.value'}, $row-&gt;{'tableA.value'}
    )  or die $dbh-&gt;errstr;
}
&lt;/c&gt;
Note that the order of the values in the execute is the order of the placeholders in the SQL, not the order the tables are opened.</field>
<field name="root_node">
659996</field>
<field name="parent_node">
659996</field>
</data>
</node>
