Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: SQL queries using dynamic array

by Enlil (Parson)
on Aug 03, 2005 at 23:59 UTC ( #480667=note: print w/ replies, xml ) Need Help??


in reply to SQL queries using dynamic array

Here is one way (granted it is not tested):

my @values = qw/Otago Auckland Nortland/; #Quote Values to be safe my $values = join("," ,map { $dbh->quote($_) } @values ); my $statement = " SELECT c_email, c_first, c_last FROM tblClient, tblGroup, tblRegion WHERE tblGroup.g_name = 'motel' AND tblRegion.r_name IN ( $values )"; my $sth = $dbh->prepare($statement); $sth->execute();

HTH

-enlil


Comment on Re: SQL queries using dynamic array
Download Code
Re^2: SQL queries using dynamic array
by jhourcle (Prior) on Aug 04, 2005 at 01:40 UTC

    For those who like bind variables:

    my $placeholders = join ( ',', ('?') x @values ); my $statement = <<"EOF"; SELECT c_email, c_first, c_last FROM tblClient, tblGroup, tblRegion WHERE tblGroup.g_name = ? AND tblRegion.r_name IN ( $placeholders ) EOF my $sth = $dbh->prepare($statement); $sth->execute('motel', @values);
Reaped: Re^2: SQL queries using dynamic array
by NodeReaper (Curate) on Nov 16, 2008 at 07:22 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://480667]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-07-31 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (254 votes), past polls