Chris wrote:
>
> <Cfset startdate = createODBCDate('8/1/2003')>
> <cfset enddate = createODBCDate('8/15/2003')>
> <cfloop index="d" from="#startdate#" to="#enddate#" step="1">
>
> <cfquery name="countReserved" datasource="#datasource#">
> Select Count (radios) as daycount
> from reservedTable
> where (StartDate <= #d#)
> AND (ReturnDate >= #d#)
> AND (radio_id = #form.inv_id#)
> </cfquery>
>
> </cfloop>
Isn't it much more efficient to get all result for all the dates
in one query?
<ffset startdate = '2003-08-01'>
<cfset enddate = '2003-08-15'>
<cfquery name="countReserved" datasource="#datasource#">
SELECT dt.countDate, Count(rt.radios) as daycount
FROM (
SELECT <cfqueryparam type="cf_sql_date" value="0000-01-01"> AS
countdate
<cfloop condition="startdate LTE enddate">
UNION
SELECT <cfqueryparam type="cf_sql_date" value="#startdate#">
AS countdate
<cfset startdate = DateAdd("d",1,startdate)>
</cfloop>
) dt, reservedTable rt
WHERE rt.StartDate <= dt.countDate
AND rt.ReturnDate >= dt.countDate
GROUP BY dt.countDate
</cfquery>
Jochem
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for
dependable ColdFusion Hosting.
http://www.cfhosting.com
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4