﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Aggregate Query and Custom Fields</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 13:39:45 GMT</lastBuildDate><ttl>20</ttl><item><title>Aggregate Query and Custom Fields</title><link>http://forum.strataframe.net/FindPost18489.aspx</link><description>I have a CustomersBO that has several custom fields to reflect order totals for the typical calendar breakdowns - week-, month-, quarter-, and year-to-date.&amp;nbsp; I have a stored procedure that summarizes these totals for me.&amp;nbsp; I use that stored procedure to fill my BO.&amp;nbsp; Here is a snippet of the sql script:&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;BR&gt;SELECT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;Customers.*, &lt;BR&gt;&amp;nbsp;(&lt;BR&gt;&amp;nbsp;SELECT &lt;BR&gt;&amp;nbsp;&amp;nbsp;SUM(SalesOrderDetails.quantity * SalesOrderDetails.unitprice) AS wtdorders &lt;BR&gt;&amp;nbsp;FROM &lt;BR&gt;&amp;nbsp;&amp;nbsp;SalesOrderDetails &lt;BR&gt;&amp;nbsp;&amp;nbsp;LEFT OUTER JOIN SalesOrderMaster ON SalesOrderMaster.orderindex = SalesOrderDetails.orderindex&amp;nbsp;&lt;BR&gt;&amp;nbsp;WHERE &lt;BR&gt;&amp;nbsp;&amp;nbsp;(SalesOrderMaster.divisionindex = @div) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color=#ff1111&gt;AND&amp;nbsp;SalesOrderMaster.custindex = Customers.CustIndex&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;AND (SalesOrderMaster.orderdate&amp;nbsp;BETWEEN @start_week&amp;nbsp;AND @enddate)&lt;BR&gt;&amp;nbsp;)&amp;nbsp;AS WTDOrders,&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;&amp;nbsp;... other lines for mtd, qtd, and ytd here&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;FROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;CustomerMaster Customers&lt;BR&gt;WHERE &lt;BR&gt;&amp;nbsp;Customers.Status = 1 &lt;BR&gt;&amp;nbsp;AND Customers.inactive = 0&lt;BR&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;The line I marked in red is my suspected line.&amp;nbsp; The query runs, but I am getting a null value for every customer (or zero, if utilize the ISNULL function), no matter what dates or division I use.&amp;nbsp; The subquery works great on its&amp;nbsp;own when I use&amp;nbsp;a specific customer index.&amp;nbsp; I thought that I had used this kind of approach to retrieving sum values before, but for some reason I cannot figure out why this does not work.&amp;nbsp; Can anyone point out where my error may be in the query?&lt;/P&gt;&lt;P&gt;Thanks!&lt;BR&gt;Bill</description><pubDate>Thu, 14 Aug 2008 10:19:22 GMT</pubDate><dc:creator>Bill Cunnien</dc:creator></item><item><title>RE: Aggregate Query and Custom Fields</title><link>http://forum.strataframe.net/FindPost18491.aspx</link><description>LOL...we have all been there...even this morning :D&amp;nbsp; Glad you got it working!</description><pubDate>Thu, 14 Aug 2008 10:19:22 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Aggregate Query and Custom Fields</title><link>http://forum.strataframe.net/FindPost18490.aspx</link><description>:blush:&lt;/P&gt;&lt;P&gt;After wrestling too long&amp;nbsp;with this query, I decided to start whacking every criteria and get it to work without any limitations (date, division or otherwise).&amp;nbsp; In the end, I discovered that my statusindex was keyed in wrong (not 1, but 3).&amp;nbsp; The query works and it works like a charm!!&amp;nbsp; It all comes down to the&amp;nbsp;"good data in, good data out" principle.&lt;/P&gt;&lt;P&gt;Sorry to bother y'all with this one.&amp;nbsp; Have a great day!&lt;BR&gt;&lt;BR&gt;:D&lt;BR&gt;Bill</description><pubDate>Thu, 14 Aug 2008 10:11:36 GMT</pubDate><dc:creator>Bill Cunnien</dc:creator></item></channel></rss>