• If what you're intending is to "explode" the range (say 1/1/2014 to 6/1/2014), then the easiest way is probably using an auxiliary Tally table. (Mine is called "Numbers" for some stupid reason.)

    Here's the query:

    SELECT CustomerNbr

    , FlagCode

    , StartDate

    , EndDate

    , DATEDIFF(m,StartDate,DATEADD(d,1,EndDate)) AS MosBetween

    , SomeNumber

    ,DATEADD(m,SomeNumber,StartDate) as TheDate

    FROM Flags CROSS JOIN SCRIDB.dbo.t_Numbers

    WHERE EndDate<='01-Jan-2015'

    AND SCRIDB.dbo.t_Numbers.SomeNumber BETWEEN 1 AND DATEDIFF(m,StartDate,DATEADD(d,1,EndDate));

    The date math might be a little off, but you get the idea. You cross join the table with dates (that you're calculating from) and the Tally or Numbers table and filter using a BETWEEN/WHERE clause.