Database update time with increment based on number of records SQL Server -


i using sql server , there's mistake in data want fix.

i want fix these data:

select *  [jbinfotech].[dbo].[leads] calldate = '1970-01-01 01:00:00.000' order id desc; 

so leads in date time 1970-01-01 01:00:00.000 there 756 of them.

what want run query like:

update [jbinfotech].[dbo].[leads] set calldate = '2016-01-28 09:12:00.000' calldate = '1970-01-01 01:00:00.000'; 

basically want update 1970's date time. possible update each of 756 records increments in minutes? let's

set calldate = '2016-01-28 09:12:00.000' 

so start , ever record there 5 minutes increment in time next record update become

set calldate = '2016-01-28 09:17:00.000'. 

because can't same value there should difference in time. possible in single query?

use cte , row_number this:

;with cte (   select *, row_number() on (order id) - 1 rn   [jbinfotech].[dbo].[leads]   calldate = '1970-01-01 01:00:00.000' ) update cte  set   calldate = dateadd(minute, rn * 5, '2016-01-28 09:12:00.000') 

Comments