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 6903671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:57:17+00:00 2026-05-27T07:57:17+00:00

I’m trying to retrieve data based on my beginning date input. If the user

  • 0

I’m trying to retrieve data based on my beginning date input. If the user selects a beginning date of 11-27-2011 and the end date is 12/04/2011, then the returned date for my data set will be for the entire month of November. If they select a beginning date of 10/01/2011 then my data set will return data from January 1 through the current date.

I have managed to get the 2nd/3rd statements working but when I try to add in the filter for retrieving data from January 1 it errors out(the first IF statement in the query). The first IF statement checks to see if the @BeginningDate is less than the month prior. If it is THEN it should retrieve the years data, else it goes on from there. Here is my query for the dates:

Declare @startdate  datetime
Declare @enddate  datetime
Declare @BeginningDate datetime

set @BeginningDate = '12-01-2011'

IF Month(@BeginningDate) < (Month(GETDATE())-1)
BEGIN
set @startdate = DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
set @enddate = dateadd(day, datediff(day, 0, getdate()), 0)
END

IF Month(@BeginningDate) = (Month(GETDATE())-1)
BEGIN
set @startdate = dateadd (mm,-1,DATEADD(dd,-(DAY(DATEADD(mm,1,convert(varchar(10),getdate(),111)))-1),DATEADD(mm,0,convert(varchar(10),getdate(),111))))--BEGINNING OF PRIOR MONTH
set @enddate =DATEADD(dd,-1,DATEADD(mm, DATEDIFF(m,0,convert(varchar(10),getdate(),111)),0))--END OF PRIOR MONTH
END

ELSE
IF Month(@BeginningDate) = (Month(GETDATE())
BEGIN
set @startdate = dateadd(month, datediff(month, 0, dateadd(day, datediff(day, 1, getdate()), 0)), 0)--BEGINNING OF CURRENT MONTH
set @enddate = dateadd(day, datediff(day, 0, getdate()), 0)--THROUGH CURRENT MONTH (TODAY)
END

As I’ve stated, I can manage to get the query to work with two of the statements but when I added in the first IF and then parsed it I get this message:

error message

Line 15 is the ‘BEGIN’ in the last ELSE statement. Am I trying to do too many IF/ELSE statements? I’ve never had to do this before as far as this many date parameters as well as using them in an IF/ELSE.

Thanks in advance!

  • 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-05-27T07:57:18+00:00Added an answer on May 27, 2026 at 7:57 am

    Looks like the line IF Month(@BeginningDate) = (Month(GETDATE()) is missing a )

    change it to this

    IF Month(@BeginningDate) = (Month(GETDATE())) and see if it works now

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.