Connecting Tech Pros Worldwide Forums | Help | Site Map

Multiple querys OR Querying query

Member
 
Join Date: Mar 2007
Posts: 94
#1: May 8 '09
Hi,

I need to produce a report in CF that extracts a range of values repeatedly from a database and displays the record count.

For example I need to extract the recordcount where a record has a PowerRating value of between 0 - 2.9, and 3 - 7.4 and so on.

I can create multiple queries:

Expand|Select|Wrap|Line Numbers
  1. select         ClientFK,
  2.             ResponseLevelFK,
  3.             PowerRating
  4.     from        tblWorkshopsNeil
  5.     where        ClientFK like '%#form.ClientFK#%' 
  6.             and (((tblWorkshopsNeil.PowerRating)>=0 And (tblWorkshopsNeil.PowerRating)<=2.9))
  7.     order by    ClientFK
  8.  
  9.  
  10.     </cfquery>
  11.  
  12.  
  13.     <cfquery datasource="repairmdb" name="qryKWBand2">
  14.     select         ClientFK,
  15.             ResponseLevelFK,
  16.             PowerRating
  17.     from        tblWorkshopsNeil
  18.     where        ClientFK like '%#form.ClientFK#%' 
  19.             and (((tblWorkshopsNeil.PowerRating)>=3 And (tblWorkshopsNeil.PowerRating)<=7.4))
  20.     order by    ClientFK
  21.  
  22.  
  23.     </cfquery>
and just return the recordcounts:

Expand|Select|Wrap|Line Numbers
  1. <cfoutput>#qryKWBand1.RecordCount#</cfoutput></p>
  2.             <p>Number of records returned: <cfoutput>#qryKWBand2.RecordCount#</cfoutput></p>
..but this seems really inefficient, and as I might need to add in further filters (such as breaking down the results by Response Level) very cumbersome.

Is there a way to run a major query then use the basis to perform further queries?

Thanks
Neil
best answer - posted by acoder
Yes, there's a feature in Coldfusion called Query of Queries.

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: May 8 '09

re: Multiple querys OR Querying query


Yes, there's a feature in Coldfusion called Query of Queries.
Member
 
Join Date: Mar 2007
Posts: 94
#3: May 11 '09

re: Multiple querys OR Querying query


Thanks acoder - great!

Neil
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: May 11 '09

re: Multiple querys OR Querying query


No problem, you're welcome :)
Reply


Similar ColdFusion bytes