Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
i have a table withid, lastname, datetime, placenow i have a blank field called lapsed timeall records should have 2 entries based on lastnamehow can i generate the lapsed time between the two entries and update this field?
UPDATE tSET t.lapsed_time=DATEDIFF(ss,b.PrevTime,t.datetime)FROM YourTable tOUTER APPLY(SELECT TOP 1 datetime as PrevTime FROM YourTable WHERE lastname=t.lastname AND id<t.id ORDER BY datetime DESC)b
If this is not giving desired result, please give some sample data of what you're looking at