ASP/SQL Server - from/to dates based on months of year

ristElilEnisp

New Member
I have an ASP page linked to SQL server. Basically I need some queries will extract all records between certain dates. I need a monthly breakdown for the last 6 months.So, this month is August (it's the 6th), so the first query needs to have a line that says\[code\]AND DATE BETWEEN '2012-08-01' and '2012-08-31'\[/code\]And I need 5 more queries which say\[code\]AND DATE BETWEEN '2012-07-01' and '2012-07-31'\[/code\]...\[code\]AND DATE BETWEEN '2012-06-01' and '2012-06-30'\[/code\]Etc. etc going back to March.Is there a way to do this? I've tried to do the following VB script but it's not giving the correct result;\[code\]ThisMonth = DateMonth1 = DateAdd("m", -1, Date)Month1From = DateAdd("d", 1, Month1 - Day(Date))Month1To = DateAdd("m", 1, Month1 - Day(Date))Month2 = DateAdd("m", -2, Date)Month2From = DateAdd("d", 1, Month2 - Day(Date))Month2To = DateAdd("m", 1, Month2 - Day(Date))Month3 = DateAdd("m", -3, Date)Month3From = DateAdd("d", 1, Month3 - Day(Date))Month3To = DateAdd("m", 1, Month3 - Day(Date))Month4 = DateAdd("m", -4, Date)Month4From = DateAdd("d", 1, Month4 - Day(Date))Month4To = DateAdd("m", 1, Month4 - Day(Date))Month5 = DateAdd("m", -5, Date)Month5From = DateAdd("d", 1, Month5 - Day(Date))Month5To = DateAdd("m", 1, Month5 - Day(Date))\[/code\]I was going to construct the SQL based on the variables, but I cannot, as the variable Month5To is showing as the 29th of Match, but there are 31 days in March. Can anyone help?
 
Back
Top