Opening dates start and end dates

I have a table like this (plus another 10 columns) containing over 1 million frequently updated records:

 id pid start_date          end_date  
  1 761 2011-07-25 00:00:00 2011-08-01 00:00:00
  2 761 2011-08-01 00:00:00 2011-08-22 00:00:00
  3 761 2011-08-22 00:00:00 2011-09-19 00:00:00
  4 802 2011-08-22 00:00:00 2011-09-19 00:00:00
  5 761 2011-06-05 00:00:00 2011-07-05 00:00:00

and would like to get the result for a specific pid (761 in the example below) with all consecutive intervals:

 id pid start_date          end_date  
  1 761 2011-07-25 00:00:00 2011-09-19 00:00:00
  5 761 2011-06-05 00:00:00 2011-07-05 00:00:00

I am currently doing this in code, but would like to completely move this functionality to the db side. Any ideas how to do this?

edit: the start_date and end_date columns are of type DATETIME.

0
source share
1 answer

It really is much better done in code. Sort through strings when they are for the same product, update the end date, otherwise create a new array record.

, , SQL, . m y SQL Server:)

0

All Articles