I have two tables and trying to update time with delta in table-1 using inner join but I am facing an issue with my below query.
SET Table-1.Time = DATEADD(minutes,,table-2.delta,table-1.time)
INNER JOIN Table-2 ON Table-1.TynameName = Table-2.Typename
AND Table1.Ordersequence >= table-2.ordersequence;
Update Table-1 set .Time= DATEADD(minutes, t2.delta, t1.time) from [Table-1] t1 cross apply (select top 1 t2.* from [Table-2] t2 where t1.Typename = t2.Typename and t1.Ordersequence >= t2.ordersequence order by t2.ordersequence desc ) t2;
The problem that you are having is that multiple rows match in
Table-2. In that case, one of the rows is arbitrarily chosen for the update. The
cross apply fixes this problem by choosing the first row that matches.