473,466 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Loop by Month

139 New Member
Hi,

I have some data I need to total by Month.

i can create a query to do this for a particular month:

Expand|Select|Wrap|Line Numbers
  1.  <cfset vStart=createDate(year(Now()), 3, 1)>
  2. <cfset vEnd=createDate(year(Now()), 3, 31)>
  3.  
  4. <cfquery name="getSum">
  5. select sum(TimeTaken) as mySum, CompletionDate
  6. from tblTaskBank
  7. where CompletionDate BETWEEN #vStart# AND #vEnd#
  8. group by TimeTaken, CompletionDate
  9. </cfquery>
  10.  

Which is great for one month, but I need to calculate the sum for each of the twelve months in a financial year (April - March).

I can loop through the dates to create start and end values:

Expand|Select|Wrap|Line Numbers
  1. <cfloop index="i" from="1" to="12">
  2.     <cfset vStartM = dateFormat(dateAdd("m", i, vStart), 'dd/mm/yyyy')>
  3.     <cfset vEndM = dateFormat(dateAdd("m", i, vEnd), 'dd/mm/yyyy')>
  4. </cfloop>
  5.  
  6.  
but how do i store these date values, then apply them to the query, and loop through the query so I get the sum for each month?

It's been doing my head in! And advice would be appreciated!

Thanks
Neil
Sep 21 '11 #1
3 4982
Rabbit
12,516 Recognized Expert Moderator MVP
I would just use
Expand|Select|Wrap|Line Numbers
  1. SELECT Month(DateField), Sum(ValueField) AS SumOfValueField
  2. FROM tableName
  3. GROUP BY Month(DateField)
Sep 21 '11 #2
ndeeley
139 New Member
hi Rabbit,

That's great thanks. Just one thing - the month value is returned as a number, which despite formatting with DateFormat doesn't display the correct month name. Do I need to use CreateODBCDate?

Thanks
Sep 22 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
You want to display the text value of the month? You do one of two things. One, in your code, use a case statement to convert the month number to text (unless such a function already exists in coldfusion, I've never used it). Or, in the SQL, get the month number, append '/01/2011' and convert that to a date and then get the month name.
Sep 22 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ken Fine | last post by:
Using ASP, I want to display a series of records grouped by nested years and months, e.g.: 2004 December Record1 Record2 Record3 November Record4
2
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a...
4
by: Tjerk Wolterink | last post by:
Hello all, i have a xsl:for-each loop like this: <xsl:for-each select="xc:agendapunt"> <xsl:sort select="xc:datum/xc:year" data-type="number"/> <xsl:sort select="xc:datum/xc:month"...
7
by: Bob | last post by:
I passed in a DateTime object, and want to get its end date of the month. Is there a easy way to do it? Thanks.
4
by: jstaggs39 | last post by:
I have a form that requires a start date and an end date as input for the parameters then runs the form which open queries which are designed to populate certain tables. As it stands now, i can...
12
by: upernikaw | last post by:
Hello, I am attempting to create a nested loop (in Access 2003/VB) that will print a report for a set of user defined months inputed on a form and that will print out for every Client. So the first...
2
by: boyleyc | last post by:
Hi all the following code works perfectly well. Basically it populates a series of check boxes on my form, depending on whether dlookup finds an associated record. The problem i have is that...
3
by: | last post by:
Hi everybody ! i'm begining with Visual Basic Express Edition and i try to make a loop month by month between two dates. I have insuccessfully tried something like this : From...
1
by: zelmila19 | last post by:
Hi can anyone tell me how to do this problem: Write a program using a while loop that asks the user to enter their sales for each month until they enter -1 (sentinel value). After this, it should...
3
by: Paulo Santos | last post by:
First of all, it's my first time here. Also, i'm working on a simple rent management program for a school project. I've fixed most of the errors but i'm lost on what could be wrong here: error:...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.