Hey guys,
I was trying to set up a SQL statement, but im still running into a few doubts.
Basically i have this select case:
VB Code:
Select Case True Case rbFirstQuarter.Checked mindate = "01/01/" & cbYear.Text & "" maxdate = "03/31/" & cbYear.Text & "" Case rdSecondQuarter.Checked mindate = "04/01/" & cbYear.Text & "" maxdate = "06/30/" & cbYear.Text & "" Case rbThridQuarter.Checked mindate = "07/01/" & cbYear.Text & "" maxdate = "09/30/" & cbYear.Text & "" Case rbFourthQuarter.Checked mindate = "10/01/" & cbYear.Text & "" maxdate = "12/31/" & cbYear.Text & "" End Select
I set up a SQL statement to get me the monthly averages of the database which looks like this:
But this statement is returning me the average of every year/month in the database. And i wanted it to return me only of the 3 months inside of the select case.Code:SELECT [Year], [Month], AVG(prod_data.val) AS AverageAmount FROM [SELECT YEAR(prod_data.valdate) AS [Year], MONTH(prod_data.valdate) AS [Month], prod_data.val FROM prod_data] GROUP BY [Year], [Month];
For example, in Case rbFirstQuarter.Checked
i wanted the average of Jan, Feb and March for the year selected in cbYear.Text
Then i wanted to make a muliplication of each of the 3 month with the equivalent from this SQL statementBut this SQL statement still need to be fixed too. I wanted it to return me the sum from #12/31/2001# to jan, the sum to feb and the sum to march.Code:SELECT DISTINCT [reference], SUM([Shares]) AS [POSITION] FROM pos_data WHERE pos_data.period Between #12/31/2001# And #" & maxdate & "# And pos_data.reference='client1' GROUP BY [reference];
Then after making the multiplication of both queries i would have 3 values: 1 for jan, 1 for feb and 1 for march.
Then i would need to get the AVG from those 3.
Does anyone know how can i do that
thx a lot in advance![]()




Reply With Quote