Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So basically i need I have a table that looks almost like this

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Name | Surname | Amount | LastDated | Number of units |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Duard | Davids | R12000 | 2012/02/05 | 54
Rick | Ford | R5500 | 2012/02/06 | 22
Fey | Morgan | | |

So this should be enough data.

I need to check the last three months data(amounts(adding them up ang getting the average)) and compare it to this months average.

so it would be John : last three months average = R 4500 ,This months average = R 8500.

so the tricky part comes in when getting empty dates(which represent the month the user didnt use the system. in which case the months need to be set back to when the user last used the system and then calculated as an average.

so I started with 4 variables

dim ThisMonth as date = dateTime.now()
dim LastMonth1 as date = thismonth.days.add(-1)
dim LastMonth2 as date = thismonth.days.add(-2)
dim LastMonth3 as date = thismonth.days.add(-3)

so when the month is empty for the LastMonth1 it has to be set back to the closest used month again,but also change the other two accordingly.

any suggestions?
Posted

1 solution

Well I can suggest you to use SQL Sum function. Here you can find more info about it.

http://www.w3schools.com/sql/sql_func_sum.asp[^]

Don't worry about null as they are ignored. Here you can find more details.

http://msdn.microsoft.com/en-us/library/ms187810.aspx[^]

Cheers
 
Share this answer
 
Comments
Member 9374423 29-Aug-12 4:21am    
Im Sorry,but could you please explain why you would use the SUM function?
Mario Majčica 29-Aug-12 4:22am    
I will not sum in the code. More efficient will be to let SQL Server do the sums via the query you are executing.
VIPR@T 31-Aug-12 6:27am    
please show your code here
Mario Majčica 31-Aug-12 7:09am    
please show your table here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900