I have a simple table with 3 columns:
(cid, from, to) -> (int, datetime, datetime)
The difference between dateFrom
and dateTo
should be >= 1 month. And unfortunately i have some corrupt data which do not satisfy this condition.
INPUT:
An example data (cid - from - to) :
8 - 01.05.2012 - 01.09.2012
8 - 02.09.2012 - 10.09.2012
8 - 11.09.2012 - 18.09.2012
8 - 18.09.2012 - 02.10.2012
8 - 03.10.2012 - 04.10.2013
DESIRED OUTPUT in a temp table:
I want to merge the dates whose interval is less than a month into 1 row:
8 - 01.05.2012 - 01.09.2012
8 - 02.09.2012 - 02.10.2012
8 - 03.10.2012 - 04.10.2013
So everything between 02.09.2012 - 02.10.2012 is merged into one row.
Is this possible using only T-SQL? (even without a cursor)
01.05.2012 - 01.09.2012
is more than 1 month but left unchanged. The next 3 rows are all less than 1 month but are combined into 1 row. The last row is also less than 1 month but left unchanged. I think you should describe more carefully your criteria. – ypercubeᵀᴹ Mar 4 '15 at 21:07