How can I condition the insertion of a record into a table in SQL Server using the T-SQL language considering the following rules:
- If the record to be inserted already exists in the table, only update the field referring to the record modification date;
- If the record still does not exist, insert the same assignment as the current date in the field for the record modification date.
For example, given the DatasBase
table with the following structure:
+--------------------------------------+
| DatesBase |
+--------------------------------------+
| PK DateBase DATETIME NOT NULL |
| DateAtualizacao DATETIME NOT NULL |
+--------------------------------------+
where, I have a record of dates used in another table with their respective update dates. We assume that we need to insert date '2013-12-12'
into this table, however, if it already exists in the table, I just need to update the DateAtualizacao
field.