Solved

cfquery results in 2nd query

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

15 Experts available now in Live!

Get 1:1 Help Now