I don't think this is a case to use explicit bind vars.

Assuming that you want to copy some columns from table1 to a new table2 based upon some parameters in table1 that won't even appear in table2, here is some code that was adapted from choroba's post:

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use DBI; my $db = 'DBI'->connect('dbi:SQLite:;db=:memory:', "", ""); $db->do('CREATE TABLE t1 (id INT, name TEXT, quantity INT)'); $db->do('CREATE TABLE t2 (id INT, quantity INT)'); my $populate = $db->prepare( 'INSERT INTO t1 (id, name, quantity) VALUES (?, ?, ?)'); $populate->execute(@$_) #some test cases that don't start with 'J' for [ 1, 'John', 12 ], [ 2, 'Jane', 14 ], [ 3, 'Jack', 16 ], [ 5, 'Joe', 22 ], [ 5, 'bobo', 33 ], [ 23,'xyz', 44 ], [ 6, 'Josh', 27 ]; my $copy = $db->prepare("INSERT INTO t2 (id, quantity) SELECT id, quantity FROM t1 WHERE name LIKE ? AND id > ?"); $copy->execute('J%',2); my $verify_t2 = $db->prepare('SELECT * FROM t2'); $verify_t2->execute; my @row; say "@row" while @row = $verify_t2->fetchrow_array; __END__ Prints: 3 16 5 22 6 27

In reply to Re: Perl DBI - Bind variable when query is inserted as part of db column by Marshall
in thread Perl DBI - Bind variable when query is inserted as part of db column by saurabh220837

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.