Solved

cfquery results in 2nd query

Posted on 2000-03-24
4
175 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 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

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…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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: …

728 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