sql >> Database >  >> RDS >> Sqlserver

Loop door elke waarde naar het volgnummer

Bedoel je dit?

with myData as
(
select ID,
row_Number() over (partition by Id order by id, StartDate) as SeqNum,
min(startdate) over (partition by Id) as minDate,
startDate, endDate
from myTable
)
select id, seqNum, startDate, endDate, dateadd(day, seqNum*29, minDate) as newDate
from myData;

Of dit:

with myData as
(
select ID,
row_Number() over (partition by Id order by id, StartDate) as SeqNum,
min(startdate) over (partition by Id) as minDate, 
max(endDate) over (partition by Id)as maxDate,
startDate, endDate
from myTable
)
select id, seqNum, startDate, endDate, 
 case 
 when maxDate < dateadd(day, seqNum*29, minDate)
 then maxDate 
 else dateadd(day, seqNum*29, minDate) end as newDate
from myData;



  1. verbinding maken met sql-server via een .net winform-toepassing

  2. MySQL-server heeft onvoldoende geheugen of start niet

  3. Hoe triggers te maken in de migratiebibliotheek van Codeigniter

  4. SQL:Vind ontbrekende mappenpaden in het splitsen van hiërarchieën