Current record:
When I update the value of current record’s activity_weightage as 2 it should pick up start_date as current_date and end_date as 31/12/2099.
and it should update the original record’s end date with today’s date.
How to write SQL with the same?
UPDATE activity_demo
SET
end_date = CURRENT_DATE
WHERE
activity_type = 'Digital - Content Syndication'
AND end_date = '31/12/2099';
INSERT INTO activity_demo (activity_type, activity_weightage, start_date, end_date)
VALUES
('Digital - Content Syndication',
2, -- New activity_weightage
CURRENT_DATE, -- Start date is today's date
'31/12/2099'); -- End date remains '31/12/2099'
I am not able to get it correct by above query.
2
Answers
A model:
fiddle
You are using a non standard date format but if you wish to continue doing so use date_format function https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_date-format