I am currently stuck in converting the dates to YTD ,MTD and QTD .

Any help is highly appreciated.

SELECT * FROM mytable
WHERE
AND data_enddate = '20140131'
ORDER BY type, data_startdate

Output from table

data_startdate data_enddate factor_name value
1/1/2014 1/31/2014 A1 0.0018
1/1/2014 1/31/2014 A2 0.0024

In this case MTD = YTD = QTD

hence the output required

displayperiod A1 A2
YTD 0.0018 0.002
QTD 0.0018 0.002
MTD 0.0018 0.002
Data for Feb

SELECT * FROM mytable
WHERE
AND data_enddate = '20140228'
ORDER BY type, data_startdate

Output from table

data_startdate data_enddate factor_name value
1/1/2014 2014-02-28 A1 0.0011
1/2/2014 2014-02-28 A1 0.0024
1/1/2014 2014-02-28 A2 0.0021
1/2/2014 2014-02-28 A2 0.0034

In this case MTD = QTD ,YTD

hence the output required

displayperiod A1 A2
YTD 0.0024 0.0034
QTD 0.0011 0.0021
MTD 0.0011 0.0021
Data for Mar

SELECT * FROM mytable
WHERE
AND data_enddate = '20140331'
ORDER BY type, data_startdate

Output from table

data_startdate data_enddate factor_name value
1/1/2014 2014-03-31 A1 0.0011
1/3/2014 2014-03-31 A1 0.0024
1/1/2014 2014-02-28 A2 0.0021
1/2/2014 2014-02-28 A2 0.0034
In this case MTD , QTD=YTD

hence the output required

displayperiod A1 A2
YTD 0.0011 0.0021
QTD 0.0011 0.0021
MTD 0.0024 0.0034
Data for Apr

SELECT * FROM mytable
WHERE
AND data_enddate = '2014-04-30'
ORDER BY type, data_startdate

Output from table

data_startdate data_enddate factor_name value
1/1/2014 2014-04-30 A1 0.0011
1/4/2014 2014-04-30 A1 0.0024
1/1/2014 2014-04-30 A2 0.0021
1/4/2014 2014-04-30 A2 0.0034

In this case MTD , QTD=YTD

hence the output required

displayperiod A1 A2
YTD 0.0011 0.0021
QTD 0.0011 0.0021
MTD 0.0024 0.0034
Data for May

SELECT * FROM mytable
WHERE
AND data_enddate = '2014-04-30'
ORDER BY type, data_startdate

Output from table

data_startdate data_enddate factor_name value
1/1/2014 2014-05-31 A1 0.0011
1/4/2014 2014-05-31 A1 0.0024
1/5/2014 2014-05-31 A1 0.0030
1/1/2014 2014-05-31 A2 0.0021
1/4/2014 2014-05-31 A2 0.0034
1/5/2014 2014-05-31 A2 0.0032

In this case MTD , QTD,YTD

hence the output required

displayperiod A1 A2
YTD 0.0011 0.0021
QTD 0.0024 0.0034
MTD 0.0030 0.0032
Data for June

June will have 3 rows

data for July

July will have 2 rows where MTD = QTD and separate YTD

Data for Aug

AUG will have 2 rows where MTD = QTD and separate YTD

Data for Sept SEPt will have 3 rows

Data for Oct Oct will have 2 rows where MTD = QTD and separate YTD

Data for NOV

Nov will have 3 rows

data for DEC

Dec will have 3 rows