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:

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!
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