in reply to Re: Calculating the range between two numbers
in thread Calculating the range between two numbers

And putting it all together we have:

my @range = ( $c .. $d ); my $rangesql = join( ', ', @range ); my $sql = "SELECT type FROM dog WHERE number IN ( $rangesql )";

Or if you're paranoid:

my @range = ( $c .. $d ); my $rangesql = join( ', ', map { $dbh->quote($_) } @range ); my $sql = "SELECT type FROM dog WHERE number IN ( $rangesql )";

Replies are listed 'Best First'.
Re^3: Calculating the range between two numbers
by jhourcle (Prior) on Jun 24, 2005 at 13:45 UTC

    If you're going to be using 'IN' a lot, and the set changes, but have a high likelyhood of having the same number of values, you may get better performance by using bind variables. (although, in the cases of numeric ranges, use 'BETWEEN' or <= and >=)

    my @set = ($c .. $d); my $sql = 'SELECT type FROM dog WHERE number IN ( ?'.(',?' x $#set).') '; my $sth = $db->prepare($sql) $sth->execute(@set);