get quarters from rolling months

Answered get quarters from rolling months

  • Monday, April 16, 2012 2:35 PM
     
     

    Hello,

    I have a table which has the first of the month field fom_dt. its rolling month.

    I need to get last 8 quarters dates and that information .

    Please tell me how can i do it.

    Thanks

    madhavi

All Replies

  • Monday, April 16, 2012 2:39 PM
     
     Answered Has Code

    hmm, something like:

    SELECT DATEADD(QUARTER, -1, fom_dt) FROM yourTable ;
    • Marked As Answer by KJian_ Monday, April 23, 2012 5:59 AM
    •  
  • Friday, April 20, 2012 8:17 PM
    Moderator
     
     

    Check out the sequence generator scripts in the following article:

    http://www.sqlusa.com/bestpractices2005/sequence/

    There are examples for temporal sequences such as days, months & quarters.


    Kalman Toth SQL SERVER & BI TRAINING

  • Friday, April 20, 2012 8:54 PM
     
      Has Code

    Dates within 8 previous quarters

    ... where  fom_dt between DATEADD(QUARTER,-8,DATEADD(QUARTER,DATEDIFF(QUARTER,'19000101',getdate()),'19000101')) and DATEADD (QUARTER, DATEDIFF(QUARTER, '19000101', getdate()), '19000101' ) - 1
    


    Serg