If you are using sql 2005/2008, you can do the following in a stored procedure.
update newTable set readKey='1' output inserted.id, inserted.readKey as readKey, deleted.readKey as prevReadKey into @tempTable where id = '1111'
You can then select from @tempTable to check if prevReadKey and readKey have a similar value, if both have a similar value, you can reset your last modified datetime.
Thus, you do not need to run multiple queries in the table in the case when the value really changes. But yes, in the case when the value does not change, this will lead to the dismissal of two update statements, where there is no need. This should be good if these cases are rare.
PS NOTE. - The specified request may be syntactically incorrect because it has not been verified. But this is exactly how your problem can be solved. I did this as follows, using the OUTPUT clause with the Merge statement in one of my projects, and this can also be done using the update statement. Here is the link in the OUTPUT section
IsmailS
source share