Solved

cfoutput group function

Posted on 2011-03-16
12
340 Views
Last Modified: 2012-05-11
One check pays for multiple invoices.

I want this output to display one check number with one or more invoice numbers in the same line.

It works fine if 1 check paid 1 invoice, otherwise it lists the check each time it was used to pay an invoice. When I use the "group" function, it will list the check once, but will only list the first invoice it paid for.

Any ideas?
SELECT *
FROM invoice
LEFT OUTER JOIN Banking ON invoice.Check_Number=banking.Check_Number

<cfoutput query="vchecks" maxrows="500" group="check_number">

Open in new window

0
Comment
Question by:aka_FATCAT
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 15

Expert Comment

by:myselfrandhawa
ID: 35153964
use the <cfoutput query="qchecks"> check @ main and inside use another question with cfoutput group attribute
0
 

Author Comment

by:aka_FATCAT
ID: 35153985
<cfoutput query="vchecks" maxrows="500">
<cfoutput group="check_number">#invoice_number#</cfoutput>
</cfoutput>

This returned every invoice number, not just the ones associated with that check.
0
 

Accepted Solution

by:
aka_FATCAT earned 0 total points
ID: 35154216
Got it.
<cfoutput query="vchecks" maxrows="500">
<cfloop query="invoicenumbers" >#invoice_number# - </cfloop>

Open in new window

0
 
LVL 15

Expert Comment

by:myselfrandhawa
ID: 35154410
@ good u found answer!
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35156568
Assuming that your check number and your invoice numbers are coming from that one query, your answer is not optimal, all you need is the group by with a 2nd set of cfoutput tags within it.

Also, to ensure the grouping works, you have to order your query by check number so the check numbers are all grouped together

SELECT *
 FROM invoice
 LEFT OUTER JOIN Banking ON invoice.Check_Number=banking.Check_Number
order by check_number, invoice_date

<cfoutput query="vchecks" maxrows="500" group="check_number">
  #check_number# - <cfoutput>#invoice_number#</cfoutput>
</cfoutput>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35159407
I agree with gdemaria's answer. It's the more optimal approach.  

<cfoutput query="vchecks" maxrows="500"

... another performance tip, limit the number of rows in the db.  The current code actually pulls every record in the 2 tables, but only displays the first X records.  If you only need 500 records, specify that in your sql.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 52

Expert Comment

by:_agx_
ID: 35159857
Got it.
<cfoutput query="vchecks" maxrows="500">
<cfloop query="invoicenumbers" >#invoice_number# - </cfloop>


Hm... on second glance, ... I don't believe that would work. At least not if there's more than 1 checknumber as your query suggests.
0
 

Author Comment

by:aka_FATCAT
ID: 35161380
Here is the complete working code.
<cfquery name="vchecks" datasource="#request.dataSource#">
SELECT *
FROM banking
WHERE 0=0
<!---LEFT OUTER JOIN Banking ON invoice.Check_Number=banking.Check_Number--->
<cfif isDefined ("URL.check_status")>
AND cstatid = '#URL.check_status#'
</cfif>
<cfif isDefined("FORM.check_date")>
AND check_date = '#FORM.check_date#'
<cfelseif isDefined("URL.check_date")>
AND check_date = '#URL.check_date#'
<cfelse>
AND check_date > '#DateFormat(startdate, "mm-dd-yyyy")#'
</cfif>
<cfif isDefined ("URL.date")>
ORDER BY check_date
<cfelse>
ORDER BY banking.check_number desc
</cfif>
</cfquery>


<cfoutput query="vchecks" maxrows="500">
<cfquery name="cstat" datasource="#request.dataSource#">
SELECT cstatid, check_status
FROM cstat
WHERE cstatid = '#vchecks.cstatid#'
</cfquery>
<cfquery name="invoicenumbers" datasource="#request.dataSource#">
SELECT invoice_number
FROM invoice
WHERE check_number = '#vchecks.check_number#'
</cfquery>

<tr>
    <td>#check_number#</td>
    <td>#DateFormat(check_date, "ddd, mm-dd-yyyy")#</td>
    <td>#pay_to#</td>
    <td><cfloop query="invoicenumbers" >#invoice_number# - </cfloop></td>
    <td>#DollarFormat(amount)#</td>
    <td>#notes#</td>
    <td>
    <cfform name="cstatus" method="post" action="/_admin/view_checks.cfm">
    <cfselect name="cstatus_select" query="cstatf" value="cstatid" selected="#cstat.cstatid#" display="check_status"/>
    <cfinput type="submit" name="submit" value="Submit">
    <cfinput type="hidden" value="#vchecks.cid#" name="cid">
    </cfform>
    
    </td>
</tr>
</cfoutput>
</table>

Open in new window

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35161700

That is one way to do it, yes.  Did you post it so we could help you do it better or just to show the "answer?"

Right now you have one main query, plus two queries that run for EVERY check number, so if there are 50 checks, you will run 101 queries.   The way agx and I suggested, you would have one query no matter what.

You will also have 50 forms instead of one form.

If you want more help, let us know, if you were just posting because you wanted to show it working, that's fine too.
0
 

Author Comment

by:aka_FATCAT
ID: 35161793
Right now, I'm just happy it's working.

If you can tell me how to do it better as in more efficiently, I would be very grateful.

Thanks.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35161895
Something like this..
<cfquery name="vchecks" datasource="#request.dataSource#">
 SELECT TOP 500
        b.*
      , inv.invoice_number
      , cs.check_status
 FROM banking b
   left join invoice inv on inv.check_number = b.check_number
   left join cstat cs on cs.cstatId = b.cstatid
 WHERE 0=0
<!---LEFT OUTER JOIN Banking ON invoice.Check_Number=banking.Check_Number--->
 <cfif isDefined ("URL.check_status")>
  AND b.cstatid = '#URL.check_status#'
 </cfif>
 <cfif isDefined("FORM.check_date")>
  AND b.check_date = '#FORM.check_date#'
 <cfelseif isDefined("URL.check_date")>
  AND b.check_date = '#URL.check_date#'
 <cfelse>
  AND b.check_date > '#DateFormat(startdate, "mm-dd-yyyy")#'
 </cfif>
 <cfif isDefined ("URL.date")>
  ORDER BY b.check_date, b.check_number desc
 <cfelse>
  ORDER BY b.check_number desc
 </cfif>
</cfquery>

<cfform name="cstatus" method="post" action="/_admin/view_checks.cfm">


<cfoutput query="vchecks" group="check_number">
<tr>
    <td>#check_number#</td>
    <td>#DateFormat(check_date, "ddd, mm-dd-yyyy")#</td>
    <td>#pay_to#</td>
    <td><cfoutput>#invoice_number# - </cfoutput></td>
    <td>#DollarFormat(amount)#</td>
    <td>#notes#</td>
    <td>
      <cfselect name="cstatus_select#vchecks.currentRow#" query="cstatf" value="cstatid" selected="#vchecks.cstatid#" display="check_status"/>
      <cfinput  name="cid#vchecks.currentRow#" type="hidden" value="#vchecks.cid#" >
    </td>
</tr>
</cfoutput>
</table>

  <cfinput type="submit" name="submit" value="Submit">
</cfform>

Open in new window

0
 

Author Closing Comment

by:aka_FATCAT
ID: 35178889
Found the answer myself.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

708 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

13 Experts available now in Live!

Get 1:1 Help Now