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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUERY IN BETWEEN DATES

Status
Not open for further replies.

kingjjx

Programmer
Sep 18, 2001
181
US
Hi, I am trying to make a search page that would allow the user to query from year X to year Y ... I have 2 drop down boxes that has a selection of years. I want it to query the years in between Year X and Year Y .. how do i write the script for this ???
thank you

-jon
 
SQL provides the BETWEEN condition to test whether a value falls between two other values. Your query would be something like this:

SELECT year
FROM table
WHERE year BETWEEN #Year1# AND #Year2#

Hope that helps.
 
<CFQUERY NAME=&quot;Displaylist&quot; DATASOURCE=&quot;DynoRunEx&quot;>
SELECT * FROM RunData WHERE 1 =1

<cfif #form.SearchMake# NEQ &quot;All&quot;>
AND RunData.Make LIKE '%#SearchMake#%'
</cfif>

<cfif #form.SearchModel# NEQ &quot;All&quot;>
AND RunData.Model LIKE '%#SearchModel#%'
</cfif>

</cfquery>

HOW DO I ADD ANOTHER CONDITION TO QUERY IN BETWEEN YEAR1 AND YEAR2 ???

THANK YOU
 
Try this:

<CFQUERY NAME=&quot;Displaylist&quot; DATASOURCE=&quot;DynoRunEx&quot;>
SELECT * FROM RunData WHERE 1 =1

<cfif #form.SearchMake# NEQ &quot;All&quot;>
AND RunData.Make LIKE '%#SearchMake#%'
</cfif>

<cfif #form.SearchModel# NEQ &quot;All&quot;>
AND RunData.Model LIKE '%#SearchModel#%'
</cfif>

<cfif IsDefined(&quot;form.SearchYear1&quot;) AND IsDefined(&quot;form.SearchYear2&quot;)>
AND RunData.Year BETWEEN #formSearchYear1# AND #form.SearchYear2#)
</cfif>

</cfquery>
 
hey, the problem with this tage:

<cfif IsDefined(&quot;form.SearchYear1&quot;) AND IsDefined(&quot;form.SearchYear2&quot;)>
AND RunData.Year BETWEEN #formSearchYear1# AND #form.SearchYear2#)
</cfif>


is I have Year1 and Year2 so I can't just use RunData.Year. I have 2 years with different names.

hope you can help
thank you
-jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top