Hi I have select CASE statement in DB2:
case when actualfinish is not null then dec (( timestampdiff(
4,
char(actualfinish - reportdate))/60.00),10,2)
else 'not'
end
It returns me error.
If I delete ELSE part there is no error and calculation is done.
case when actualfinish is not null then dec (( timestampdiff(
4,
char(actualfinish - reportdate))/60.00),10,2)
end
If I change THEN part to something like
case when actualfinish is not null then 'Yes'
else 'not'
end
also there is no error.
But for my complete SQL query – can’t find an error.
Thanks
Issue here is that
decfunction returns a decimal datatype in the else part of the CASE statement you are returning a VARCHAR, hence the issue.In your second version
case when actualfinish is not null then 'Yes'else 'not'
end
Both the
whenandelseare returning same datatype hence the query runs fine.Change your else to send a decimal equivalent value and it should execute fine.
Update:
Use this version if you can return decimal as a string: