Dynamic update for all writes for VehiclePreviousLog
This commit is contained in:
@@ -10,9 +10,11 @@ namespace MileageTraker.Web.Migrations
|
||||
AddForeignKey("Log", "VehiclePreviousLogId", "Log", "LogId");
|
||||
CreateIndex("Log", "VehiclePreviousLogId");
|
||||
var populateSql =
|
||||
@"WITH summary AS (
|
||||
@"WITH summary AS (
|
||||
SELECT
|
||||
ROW_NUMBER() OVER (PARTITION BY l.LogId ORDER BY l.LogId ASC, pl.EndOdometer DESC, pl.Created DESC) AS rk,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY l.LogId
|
||||
ORDER BY pl.EndOdometer DESC, pl.Created DESC) AS rk,
|
||||
l.LogId, pl.LogId as PreviousLogId
|
||||
FROM
|
||||
[Log] as l,
|
||||
@@ -22,7 +24,7 @@ namespace MileageTraker.Web.Migrations
|
||||
AND ((pl.[Date] <= l.[Date]
|
||||
AND pl.EndOdometer < l.EndOdometer)
|
||||
OR (
|
||||
pl.EndOdometer < l.EndOdometer
|
||||
pl.EndOdometer = l.EndOdometer
|
||||
AND pl.Created < l.Created
|
||||
))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user