how do i create Periods and weeks (think business reports) using 2 date ranges Basically Fromdate is every Sunday and ToDate is every saturday, i need to programatically create the PERIOD column on the fly through a stored procedure where period is the month and week is the week of that month, 

--but there shouldnt be 5 weeks in a period.
FromDate    ToDate      PERIOD
2015-11-29  2015-12-05  P12-WK1 &lt;-- see how it goes to the next period
2015-11-22  2015-11-28  P11-WK4
2015-11-15  2015-11-21  P11-WK3
2015-11-08  2015-11-14  P11-WK2
2015-11-01  2015-11-07  P11-WK1


I tried using the code below but my results are slightly off, 

for example 

2016-01-17  2016-01-23  P1-WK4 should be 

2016-01-17  2016-01-23  P1-WK3 (notice the WK)

CASE datediff(week, dateadd(month, datediff(month, 0, dbo.GP_MASTER.FromDate), 0), dbo.GP_MASTER.FromDate) + 1
WHEN 5 THEN 'P' + CAST(DATEPART(M, dbo.GP_MASTER.FromDate + 1)AS varchar(20)) + '-WK'+ CAST(datediff(week, dateadd(month, datediff(month, 0, dbo.GP_MASTER.FromDate), 0), dbo.GP_MASTER.FromDate)  AS varchar(20))
WHEN 6 THEN 'P' + CAST(DATEPART(M, dbo.GP_MASTER.FromDate + 2)AS varchar(20)) + '-WK'+ CAST(datediff(week, dateadd(month, datediff(month, 0, dbo.GP_MASTER.FromDate), 0), dbo.GP_MASTER.FromDate) - 4 AS varchar(20))
ELSE        'P' + CAST(DATEPART(M, dbo.GP_MASTER.FromDate)AS varchar(20)) + '-WK'+ CAST(datediff(week, dateadd(month, datediff(month, 0, dbo.GP_MASTER.FromDate), 0), dbo.GP_MASTER.FromDate) + 1 AS varchar(20))
END AS PERIOD

2016-02-21  2016-02-27  P2-WK4
2016-02-14  2016-02-20  P2-WK3
2016-02-07  2016-02-13  P2-WK2
2016-01-31  2016-02-06  P2-WK1
2016-01-24  2016-01-30  P1-WK4
2016-01-17  2016-01-23  P1-WK4
2016-01-10  2016-01-16  P1-WK3
2016-01-03  2016-01-09  P1-WK2


This is my desired results 

FromDate    ToDate      PERIOD (Period# - Week#)
2016-02-21  2016-02-27  P2-WK4
2016-02-14  2016-02-20  P2-WK3
2016-02-07  2016-02-13  P2-WK2
2016-01-31  2016-02-06  P2-WK1
2016-01-24  2016-01-30  P1-WK4
2016-01-17  2016-01-23  P1-WK3
2016-01-10  2016-01-16  P1-WK2
2016-01-03  2016-01-09  P1-WK1
I would suggest that you create a Calendar Table that you can use for decades to come.  You create it once and use if for almost forever.

Examples: 

Aaron Bertrand's Creating a date dimension or calendar table in SQL Server

Himanshu Sharma &amp; Mohammad Nizamuddin in TechNet T-SQL: Calendar Table