can you change your inputs to a datetime value representing the any day within your target month? If so, this would work:declare @startDate datetimeset @startDate = '2011-09-01'select DATENAME(month, calender.dt) ,datepart(day, calender.dt) ,yt.namefrom ( select DATEADD(day, number, @startDate) dt from master..spt_values where type = 'P' and number < 31 and datediff(month,@startDate, dateadd(day, number, @startdate)) = 0 ) calender JOIN YourTable yt on yt.startDate <= calender.dt and yt.enddate >= calender.dt
This uses an adhoc calender derived table. If you want the Cadillac of calender functions:Date Table Function F_TABLE_DATE from MVJ would certainly do the trick.Be One with the OptimizerTG