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!

Select Range Between Two Fields

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
Is there an SQL way of selecting all the values between and including two integer fields that are in a single given record? For example, if one is 1957 and the other is 1965, I need all years between and including those two. I know I can do it using PHP or other programming but I am trying to come up with an SQL way, if one exists.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
If you had a table called "years" containing one field (called "y"), and it was loaded a record for each year within the range you are likely to be dealing with, then you could use something like:
[tt]
SELECT *
FROM years
WHERE
y
BETWEEN (SELECT field1 FROM tblname WHERE id='123')
AND (SELECT field2 FROM tblname WHERE id='123')
[/tt]
 
Yes, thanks, I know (I do it all the time) but what I am trying to do is to get a range from two fields in a single record. Never mind, though, since I decided to do it programatically.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top