sql - Update table with new value for each row -


i need update column (type of datetime) in top 1000 rows table. catch each additional row must increment getdate() 1 second... dateadd(ss,1,getdate())

the way know how this:

update tablename    set columnname = case id                         when 1 dateadd(ss,1,getdate())                         when 2 dateadd(ss,2,getdate())                         ...                     end 

obviously not plausible. ideas?

i don't know id like, , i'm assuming have @ least sql server 2008 or else row_number() won't work.

note: did top 2 show you top works. can change top 1000 actual query.

declare @table table (id int, columnname datetime); insert @table(id)     values(1),(2),(3);  update @table set columnname =  dateadd(second,b.row_num,getdate()) @table inner join              (             select top 2 *, row_number() on (order id) row_num             @table             order id             ) b on a.id = b.id   select * @table 

results:

id          columnname ----------- ----------------------- 1           2015-03-31 13:11:59.760 2           2015-03-31 13:12:00.760 3           null 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -