I want to run this code only once in an agent job that gets hit every 5 minutes:
UPDATE mytable
SET text_column = (CONCAT('Added text - ', text_column))
WHERE status IN ('status1', 'status2', 'status3')
AND other_criteria IN ('other_criteria1', 'other_criteria2', 'other_criteria3');
New records may get inserted any time of day and night - which is why the job runs every 5 min.
text_column
may or may not be NULL when the record is inserted (which doesn't matter but, prevents me from using ISNULL in my where clause.)
status
may change on the fly before the job runs (which also doesn't matter except that I cannot update the above query to only run against those specified statuses and then change the status after to ensure that the update doesn't happen again [because other transactions may still need to happen while the record is in whatever status].)
other_criteria
is generally static information but, it is by no means unique...
So, what I want to happen is basically:
5 minute job runs - the new record = status1 & other_criteria1 gets the text_column set to 'Added_text - (text_column)'
Then I want to avoid having this record's text column set to 'Added text - Added text - (text_column)' the next time the job runs even when it still matches the "status" and "other_criteria" in my where clause...
Is this possible without getting more specific in my where clause?