Could you not just have the value as a computed column, then there is no need to update, as it's calculated? For example:USE DevTestDB;
GO
CREATE TABLE Dates (ID INT IDENTITY(1,1),
Start_Date DATETIME,
End_Date DATETIME,
DIFF AS (DATEDIFF(MINUTE,Start_date,End_Date)));
GO
INSERT INTO Dates (Start_Date, End_Date)
VALUES ('15-Jan-2016 19:19:19.000', '15-Jan-2016 20:20:20.000'),
('16-Jan-2016 10:10:00.000', '16-Jan-2016 16:45:22.000');
GO
SELECT *
FROM Dates;
UPDATE Dates
SET End_Date = '16-Jan-2016 12:17:22.000'
WHERE ID = 2;
SELECT *
FROM Dates;
GO
DROP TABLE Dates
This brings back the following respectively:ID Start_Date End_Date DIFF
----------- ----------------------- ----------------------- -----------
1 2016-01-15 19:19:19.000 2016-01-15 20:20:20.000 61
2 2016-01-16 10:10:00.000 2016-01-16 16:45:22.000 395
(2 row(s) affected)
ID Start_Date End_Date DIFF
----------- ----------------------- ----------------------- -----------
1 2016-01-15 19:19:19.000 2016-01-15 20:20:20.000 61
2 2016-01-16 10:10:00.000 2016-01-16 12:17:22.000 127
(2 row(s) affected)
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk