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:
  1. Select Case True
  2.                 Case rbFirstQuarter.Checked
  3.                     mindate = "01/01/" & cbYear.Text & ""
  4.                     maxdate = "03/31/" & cbYear.Text & ""
  5.                 Case rdSecondQuarter.Checked
  6.                     mindate = "04/01/" & cbYear.Text & ""
  7.                     maxdate = "06/30/" & cbYear.Text & ""
  8.                 Case rbThridQuarter.Checked
  9.                     mindate = "07/01/" & cbYear.Text & ""
  10.                     maxdate = "09/30/" & cbYear.Text & ""
  11.                 Case rbFourthQuarter.Checked
  12.                     mindate = "10/01/" & cbYear.Text & ""
  13.                     maxdate = "12/31/" & cbYear.Text & ""
  14.             End Select

I set up a SQL statement to get me the monthly averages of the database which looks like this:
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];
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.

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 statement
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];
But 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.

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