Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Using BETWEEN operator in a SELECT

Quote Reply
Using BETWEEN operator in a SELECT
I am starting a new thread, as my prevoious "Select woes" is still an open ticket - so to speak.

I know there is a BETWEEN operator in SQL. How do I use this using the GT condition statement or something similar?

For example, selecting the number of links with hits between 6 and 10:

$lt->select( GT::SQL::Condition->new('Hits', '<>', 6-10) )->rows;

EDIT:I am thinking the only way might be:

my $cond = GT::SQL::Condition->new(
'Hits', '>', '5',
'Hits', '<', '11'
);
$cond->bool('AND'); <<- can I put this inside the GT::SQL::Condition->new('Hits', '<>', 6-10) ?


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 14, 2002, 8:32 PM
Quote Reply
Re: [Ian] Using BETWEEN operator in a SELECT In reply to
Hi,

You could do:

$t->select(GT::SQL::Condition->new('Hits', 'BETWEEN', \'6 AND 10'));

which translates to:

SELECT * FROM TABLE WHERE Hits BETWEEN 6 AND 10

Because you backslash the value, it's not quoted, so if you are basing the 6 and 10 off user input, be sure to check it first to make sure they are numbers.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Using BETWEEN operator in a SELECT In reply to
Alex, you are doubling my knowledge of SQL in Links this afternoon! Thanks againCool


http://www.iuni.com/...tware/web/index.html
Links Plugins