• Maybe this code will give you an idea.

    DECLARE @FYint=14,

    @P int=3;

    DECLARE @Date date

    SET @Date = CAST( @FY as CHAR(2)) + RIGHT( '0' + CAST( @P AS varchar(2)), 2) + '01'

    SELECT @Date LastPeriod, DATEADD( MM, -11, @Date) AS FirstPeriod.

    SELECT DATEADD( MM, -n, @Date)

    FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11))Tally(n)

    ORDER BY n DESC

    As Lynn said, we can't see your information, so any further help would need some help from you. Post the information that Lynn asked and we'll be glad to help.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2