Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"expr BETWEEN ... AND ..." with @variable syntax problems...

Status
Not open for further replies.

shadedecho

Programmer
Oct 4, 2002
336
US
I am having a great deal of difficulty finding sufficient documentation on the "BETWEEN ... AND" operator functionality in MySQL, in particular, how (if possible) to use it with a variable.

Before I ask that question though, a little ground work: You may be familiar with the ability to query MySQL without referencing a table, such as:

SELECT TO_DAYS('2002-01-15') AS 'datevar'

would return:

datevar
_______
731230

I would like to use this ability as well as "BETWEEN ... AND" to have MySQL return a result set with a range of values... for instance, something like this:

SELECT @a WHERE @a BETWEEN 3 AND 8

and have MySQL return a result set like this:

3
4
5
6
7
8

Can anyone help me with how I would syntactically structure such a query?
 
What I was getting at (but didn't actually come out and say) in my previous post was that I wanted to set up a looping construct whose "terminating condition" was a false from the BETWEEN ... AND logical constructor. Does anyone know how to do this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top