Reputation: 1
I'm a bit new to sql and couldn't get this. how can i update the date of column when the data is received by one column and that matches a certain value then the date should be automatically updated in a column
Here is my table how it looks like
Id level level_4_Updated level_5_updated level_6_updated
1....4.............Null........................Null.......................Null
2....5.............Null........................Null.......................Null
3....6.............Null........................Null.......................Null
4....5.............Null........................Null.......................Null
5....4.............Null........................Null.......................Null
if the actual_level is 4 then the date should be updated in the level_4_updated and if level is 5 then the date should be updated in level_5_updated automatically when the level get the data. and the update of each row should be independent. if we update any row it should not effect the other rows. Can i get the query for this with out using triggers.
Thank you in advance
Upvotes: 0
Views: 47
Reputation: 1269513
Is this what you are looking for?
update t
set level_4_Updated = (case when level = 4 then now() else level_4_Updated end),
level_5_Updated = (case when level = 5 then now() else level_5_Updated end),
level_6_Updated = (case when level = 6 then now() else level_6_Updated end)
where id = @id;
Upvotes: 1
Reputation: 756
Firstly, I think that English is not your first language !
When you say "date", I think that you mean data or data entry.
So what you are trying to do is apply a data entry into a column called "updated-level_i" where the column called "level" holds the value i.
You simply write a stored procedure to go through each row of data in your table, get the data-entry in the "level" column, assign an appropriate update column based on this value and then execute an update on this column.
Upvotes: 0