SQLTeam.com | Weblogs | Forums

Update data automatically


Hi everyone
am new to the forum and i need your help please .
I have a table with 3 columns : column A, column B, column C .
in column B in every release there is new data that are saved i
i need to writ a function that compare the old data in column B with the new one and see if there is any new data if so add it automatically in the column C .
Thankyou in advance .


Where do you have your new data? Is that in the same table, or in another temporary table perhaps?

update a set
   ColumnC = b.ColumnB
   PermanentTable as a
   inner join TempTable as b ON
      a.ColumnA = b.ColumnA
   a.ColumnB <> b.ColumnB;


In the same table , but i want to stor it in the column C i mean the new data that is in column B


An alternative way to do this is to have an "Audit table", with the same columns as the main table (plus an additional column for ChangedDate/Time) and then to use a TRIGGER to save the previous values into the Audit Table whenever a row(s) is/are changed in the Main Table.

Dunno if that would suit your needs, I'm just mentioning it in case of interest :slight_smile: