Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Calculate last 3 Month End/Quarter End Dates Expand / Collapse
Author
Message
Posted Thursday, September 24, 2009 10:31 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, June 16, 2010 12:45 PM
Points: 101, Visits: 65
Hi,
I am creating a report which has input as date (which is a month end Date) and option to run Monthly/Quarterly. If Monthly option is selected then for the selected date, the report should run for selected month end and previous 3 month ends showing summary data. Similarly if Quarterly option is selected and quarter end date is entered then it should run for selected quarter and previous 3 quarter ends showing summary data.

Eg. for Monthly. If 08/31/2009 is selected, need to calculate previous
3 month end dates: 07/31/2009, 06/30/2009, 05/31/2009

Eg. for Quarterly. If 06/30/2009 is selected, need to calculate previous
3 quarter end dates: 03/31/2009, 12/31/2008, 09/30/2008 (based on the Calender Year)

Thanks,
Post #793420
Posted Thursday, September 24, 2009 12:53 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Sunday, September 7, 2014 11:27 PM
Points: 7,164, Visits: 13,257
duplicate post.
discussion already started here .




Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #793514
Posted Thursday, September 24, 2009 1:06 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, June 16, 2010 12:45 PM
Points: 101, Visits: 65
It took lot of time for formatting the sample 3 line summary data. I tried to delete/edit the post (from original content) but I couldn't find such an option in this forum. It would be good to have such an option atleast for the person who is trying to post and if it accidently gets posted/ doesn't get formatted properly.
Next time I shall try to post the Questions properly.
Anyway thanks for your time and keep up the good work!

By the way I have found the solution for what I was looking for.

Have wonderful day!
Post #793522
Posted Tuesday, April 27, 2010 7:30 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 16, 2014 10:34 AM
Points: 13, Visits: 1,010
I got a request from one of our groups to create a report by quarter with the option of monthly. Can you tell me where you found your answer please. ...
Post #911098
Posted Tuesday, April 27, 2010 8:26 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, June 16, 2010 12:45 PM
Points: 101, Visits: 65
Assuming user enters the input report run date as @ReportDate and you need to generate the report for previous month and previous quarter, below is how I have calculated the Previous Month Begin Date & End date and Previous Qtr Begin Date & End Dates:


----Set the last month end and last month beginning for the monthly report

DECLARE @LAST_MONTH_BEG DATETIME
DECLARE @LAST_MONTH_END DATETIME

SET @LAST_MONTH_END = DATEADD(D, 0, DATEDIFF(D, 0, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@ReportDate),0))))
SET @LAST_MONTH_BEG = DATEADD(DD, 1 - DAY(@LAST_MONTH_END), @LAST_MONTH_END)

----Set the Last Quarter End (for calendar year) and Last Quarter beginning for the Quaterly report

DECLARE @LAST_Q_BEG DATETIME
DECLARE @LAST_Q_END DATETIME

SET @LAST_Q_BEG = DATEADD(q,DATEDIFF(q,0,@ED)-1,0)
SET @LAST_Q_END = DATEADD(D, 0, DATEDIFF(D, 0, dateadd(s,-1,DATEADD(q,1,@LAST_Q_BEG))))


Post #911172
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse