?
Solved

cfquery results in 2nd query

Posted on 2000-03-24
4
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
peteodonnell earned 800 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

762 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