Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:39:18+00:00 2026-06-09T03:39:18+00:00

I have an ASP page linked to SQL server. Basically I need some queries

  • 0

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

AND DATE BETWEEN '2012-08-01' and '2012-08-31'

And I need 5 more queries which say

AND DATE BETWEEN '2012-07-01' and '2012-07-31'

…

AND DATE BETWEEN '2012-06-01' and '2012-06-30'

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;

ThisMonth = Date
Month1 = 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))

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:39:20+00:00Added an answer on June 9, 2026 at 3:39 am

    Why not change your query to filter on

     WHERE MONTH(date)= @m AND YEAR(date) = @y
    

    You could also get all the results in one result set using a GROUP BY query

    Also note that your original query will fail should the date values have any times attached.

    ie: 2012-07-31 09:15 is not between ‘2012-07-01’ and ‘2012-07-31’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp page with Timer control. Timer control will trigger some method
I have asp label in my asp page and its text is some my
I have ASP.NET page with an iframe on it for displaying some pdf reports
I have an asp page with some Textbox controls on it. By default, the
I have asp.net page where some file manipulation is performed. So when user click
I have ASP.NET page, it calls webservice via $.ajax and returns result in json
I have an asp page in which the are number of listboxes.I want to
I have an asp page that loads a response user=exists everytime I try to
I have an ASP page which displays a text box when it loads. It
I have a ASP Page and it has so many date variables. myvariable =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.