Below is my final working solution. It turns out that moving this...
date_modified = (CASE
WHEN name <> values(name)
OR description <> values(description)
OR status <> values(status)
OR type <> values(type)
OR priority <> values(priority)
THEN UTC_TIMESTAMP()
ELSE date_modified
END),
to the top of the list, above these fields...
name='$name',
description='$description',
status='$status',
priority='$priority',
type='$type',
So the final solution looks like this below...
$sql = "
INSERT INTO
$this->tasksDbTableName(task_id, project_id, name, description, status, priority, type, date_entered, date_modified, sort_order, heading)
VALUES
('$taskId', '$projectId', '$name', '$description', '$status', '$priority', '$type', UTC_TIMESTAMP(), UTC_TIMESTAMP(), '$sort_order', '$heading')
ON DUPLICATE KEY UPDATE
date_modified = (CASE
WHEN name <> values(name)
OR description <> values(description)
OR status <> values(status)
OR type <> values(type)
OR priority <> values(priority)
THEN UTC_TIMESTAMP()
ELSE date_modified
END),
name='$name',
description='$description',
status='$status',
priority='$priority',
type='$type',
sort_order='$sort_order',
heading='$heading'";
Just moving my CASE Statement
to the top above the other set fields, made it start working correctly!
It almost seems as if these DB column fields name
description
status
priority
type
were getting Updated before my Case statement could run which resulted in them always appearing to be the same as the DB fields and never any different so my Case statement was about useless. Moving it to the top, it now works 100% correctly.
Hopefully this will help someone with a similar problem someday as many people across 3 sites tried to fix it without success. Just moving it to the top did the trick though so the Order in this case very much matters!
]
Thanks to all that have contributed their time to try and find a solution, I always appreciate the help I receive on the StackExchange network sites!
Not sure what you mean, but I think you are looking for something like this:
Case
when A_staff_Service_Type.type = 'v' and pt_service.service_code = 'N06'
then isnull(Indirect_Duration,0)/60.00 + isnull(direct_Duration,0)/60.00
else null
end
I also don't know if the AND
is correct for your use-case. Maybe you want an OR
- but based on the little information you have provided this is impossible to answer.
The obvious answer to "I want the results added" is:
Case when A_staff_Service_Type.type = 'v'
then isnull(Indirect_Duration,0)/60.00 else 0 end
+
Case when pt_service.service_code = 'N06 '
then isnull(direct_Duration,0)/60.00 else 0 End
Best Answer
Please try below code for your issue: