Good day perl monks, I am wanting to use an SQL query that will use an array as part of the WHERE clause. The original query looks something like this
# // Connect to Microsoft SQL 2000 Database
my $DSN = 'driver={SQL Server};Server=DIGGER;database=Mailbird;uid=dig
+ger;pwd=psswrd;';
my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n";
# Prepare the SQL statement
my $sth = $dbh->prepare( <<SQL );
SELECT c_email, c_first, c_last
FROM tblClient, tblGroup, tblRegion
WHERE tblGroup.g_name = 'motel'
AND tblRegion.r_name='Otago'
SQL
# Execute the SQL statement
$sth->execute;
Where the query states 'Otago' I am wanting to use an array containing a list of values (eg Otago, Auckland, Northland etc). There for the query would be something like
AND tblRegion.r_name='Otago' OR tblRegion.r_name='Auckland' OR tblRegi
+on.r_name='Northland ...
I have looked at joining this array into one variable, with little success.
How should I approach this?
Forever greatfull
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.