>Thanks sir for helping
>
>But
>
>These codes will not update nSeconds column in SQLserver table.
>
>I need for sqlserver, please
For SQL you would need a strictly incremental key, or else you wouldn't be able to say what is the previous record - there is no "previous record" there, as the physical order of records is not guaranteed by anything. You wouldn't even be able to write updates without a key, bescause there's no "current record" either. Instead, each update statement needs a where clause.
Also, instead of VFP trick of using the same cursor twice, in SQL you would have to use a self-join in the update statement, which is where it gets complicated and, believe it or not, I haven't done it.
Perhaps an easier way would be to
declare @dmx, @dnow datetime;
select @dmx=max(date) from junk
select @dnow=getdate()
insert into junk (date, nseconds) values (@dnow, datediff(seconds, @dnow, @dmx)
IOW, don't write values without seconds and fill them in later - calculate them from the max datetime before inserting. If it's not the current datetime that you're inserting, then it's a different matter - this would be a stored procedure where you'd pass @dnow as a parameter, and the 2nd line would be
select @dmx=max(date) from junk where date<@dnow