title: Divide rows with date in SQL Server 2014
body: <p>I have a problem with SQL. I have the following table:</p>
  
  <pre><code>declare @t table (START_DATE datetime,
                    END_DATE datetime, 
                    GROSS_SALES_PRICE decimal(10,2)
                   );
  
  insert into @t 
  values ('2014-08-06 00:00:00.000', '2014-10-06 23:59:59.000', 29.99),
         ('2014-09-06 00:00:00.000', '2014-09-09 23:59:59.000', 32.99),
         ('2014-09-10 00:00:00.000', '2014-09-30 23:59:59.000', 32.99),
         ('2014-10-07 00:00:00.000', '2049-12-31 23:59:59.000', 34.99)
  </code></pre>
  
  <p>I would like to separate the dates which overlaps. For example I have in the first row START_DATE 2014-08-06 and END_DATE 2014-10-06. We can see that the dates from the second and the third row are inside this period of time from first row. </p>
  
  <p>So I would like to separate them as follows:</p>
  
  <pre><code>declare @t2 table (START_DATE datetime,
                     END_DATE datetime, 
                     GROSS_SALES_PRICE decimal(10,2)
                    );
  
  insert into @t2 
  values ('2014-08-06 00:00:00.000', '2014-09-05 23:59:59.000', 29.99),
         ('2014-09-06 00:00:00.000', '2014-09-09 23:59:59.000', 32.99),
         ('2014-09-10 00:00:00.000', '2014-09-30 23:59:59.000', 32.99),
         ('2014-10-01 00:00:00.000', '2014-10-06 23:59:59.000', 29.99),
         ('2014-10-07 00:00:00.000', '2049-12-31 23:59:59.000', 34.99)
  </code></pre>
  
  <p>So the second and the third rows remained unchanged. The first row should have new END_DATE. We also have new row. The GROSS_SALES_PRICE should remain as it is in internal period. Thanks for help. I am using SQL Server 2014</p>