Skip to content
Advertisement

How to update last record with second lat results [SQLServer]

I want to update the last entry of the table with Pass/Fail result from the second last row. And the query need to didnt fail if only one row is in the table.

Here is the code what i have, but ist only update with the first entrys and not the the second last entrys. thx for help

SQL Server Version: 9.0.5057

Advertisement

Answer

I’m not sure I’m following. Given data like this:

You want to update the row with TestergebnisID = 3 with Pass and Fail from record with TestergebnisID = 2 and that’s it? Or should record 2 be updated with data from record 1 too?

In case of the former, this should do the trick:

Gives:

If you want all of them to be updated with their predecessors’ values, then:

This will update rows 2 (from 1) & 3 (from 2):

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement