Solved

cfquery results in 2nd query

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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