Solved

cfquery results in 2nd query

Posted on 2000-03-24
4
169 Views
Last Modified: 2013-12-24
I have a column in a SQL database named dogs.  I want to query for all records in that column that are not null then get a record count for each breed of dog.  I have sucessfully queried for all records that are not null but need to know how to pass the results to another query to get the record number for each breed.
Thanks,
Kim
0
Comment
Question by:kimcarr
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
peteodonnell earned 200 total points
ID: 2655117
try this,

-assume your first query which get all not null dogs is called yourFirstQuery

<cfloop query="yourFirstQuery">
  -set a variable to yourFirstQuery.dogBreed
  <cfquery name=#yourFirstQuery.dogBreed
#_Query datasource=youDataSource>
    SELECT count(*) FROM dogTable WHERE dogBreed = '#theVariable#'
  </cfquery>
  -now you have counting querys for each breed of dog named for the particular dog
  -#yourFirstQuery.dogBreed#_Query.count should have the number of the breed for the dog in variables.dogBreed
</cfloop>

good luck

0
 

Author Comment

by:kimcarr
ID: 2655265
Ok, I have it producing the distinct names but the count is coming up as 0 for every record.  I have posted my queries below.  Thanks for your help!
Kim

<cfquery name="GetDepr" datasource="dre_new" dbtype="ODBC">
            Select Distinct(Conf_CNS_Depr_list)
            from dreeval
            Where dreeval.Conf_CNS_Depr_list <> 'none'
            Order by Conf_CNS_Depr_list
</cfquery>
<cfloop query="GetDepr">
      <cfset DeprUsed = "GetDepr.Conf_CNS_Depr_list">
            <cfquery name="GetDeprUsed" datasource="dre_new" dbtype="ODBC">
                  Select count(*) as DeprNum
                  from dreeval
                   where Conf_CNS_Depr_list ='#Variables.DeprUsed#'
            </cfquery>
</cfloop>
<table>
<cfoutput query="GetDepr">
#GetDepr.Conf_CNS_Depr_list# -  #GetDeprUsed.DeprNum#<br>
</cfoutput>
</table>
0
 

Author Comment

by:kimcarr
ID: 2655339
I found one problem
<cfset DeprUsed = "GetDepr.Conf_CNS_Depr_list">
and changed the code to
<cfset DeprUsed = "#GetDepr.Conf_CNS_Depr_list#">
but now I am getting just one record count for each type.
Thanks,
Kim
0
 
LVL 2

Expert Comment

by:peteodonnell
ID: 2661083
Your code only creates one query.  You need to name the query (2nd) something with the particular breed in the title i.e. #DeprUsed#_CountQuery.  That way you get separate and different queries for each breed and can do a similar loop to go through those queries.  Presently your code only creates one query and executes it for each breed.  I would guess that the breed table only has one record of that type.  You're almost there, good luck.

-Pete
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now