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.
Author |
Topic |
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2014-07-03 : 13:10:58
|
Hi All,I have one table with 100000 records and now i have to update one column in that. Below is the scenarioI have to update Last_First_Date column based on RowNo. So that previous row first date will be the next row last dateRowNo First_Date Last_First_Date1 7/2/14 7:07 AM 2 7/2/14 7:03 AM 7/2/14 7:07 AM3 7/2/14 7:09 AM 7/2/14 7:03 AM4 7/2/14 7:24 AM 7/2/14 7:09 AM5 7/2/14 7:34 AM 7/2/14 7:24 AMPlease suggest |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-07-03 : 13:18:08
|
[code]UPDATE tgtSET tgt.Last_First_Date = (SELECT TOP(1) src.First_Date FROM dbo.Table1 AS src WHERE src.RowNo < tgt.RowNo ORDER BY src.RowNo DESC)FROM dbo.Table1 AS tgt[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2014-07-05 : 11:52:45
|
Awesome SwePeso |
|
|
|
|
|