I've got a table like (code in SAS SQL but I can convert reply from SQLServer engine as I have a bit of experience in it):
proc sql;
create table work.temp1
(date_from num informat=date7. format=date7.,
date_to num informat=date7. format=date7.,
some_number num);
insert into work.temp1
values('15MAY2018'd,'26JUL18'd, 10);
QUIT;
result:
and I want convert it to (with some clever join and probably some temp table with dates and months) to:
proc sql;
create table work.temp2
(date_from num informat=date7. format=date7.,
date_to num informat=date7. format=date7.,
some_number num);
insert into work.temp2
values('15MAY2018'd,'31MAY18'd, 10)
values('1JUN2018'd,'30JUN18'd, 10)
values('1JUL2018'd,'26JUL18'd, 10);
QUIT;
result:
All of other columns should be duplicated. Dates from and to are always in one calendar date but each row can be in different year (2016-2020).
[EDIT]:
Tom solution looks good but before I use, I am trying to develop SQL solution.
I've added a "calendar" table to my db and it looks like:
name: work.calendar
Now the join I am thinking about would be something like:
SELECT t1.*
FROM work.temp1 t1 INNER JOIN
work.calendar t2 ON t1.date_from >= t2.month_FROM AND t1.date_to <= month_TO
But it doesn't work obviously.