I'm using MySql and I have a Policy
table with StartDate
and EndDate
columns.
How can I write a SELECT
query to give me a new row for each month in the date range between these 2 columns.
For example if I have a policy with:
Id StartDate EndDate
123456 2011-05-25 2011-07-26
I would want to see:
Id PolicyId StartDate EndDate
1 123456 2011-05-25 2011-06-24
2 123456 2011-06-25 2011-07-24
3 123456 2011-07-25 2011-07-26
I'm not sure about performance because I'm not much experienced with stored procedures so there might be a better approach. Also, you might want to change the structure of the temporary table (aka.
PolicyList
). Anyway…This can also be converted into before/after triggers instead of executing it each time.
and then query: