'ERROR: syntax error at or near "case" Position: 226
select
case when cld.last_milestone='APPROVED' THEN clf.application_received_and_approved_at
case when cld.last_milestone='LOCK' THEN clf.locked_at
case when cld.last_milestone='FUNDING' THEN clf.funded_at
end as Last_Milestone_at
from
core.loan_file_milestone_days as clf
I CANNOT UNDERSTAND WHAT WENT WRONG HERE?
Solution 1:[1]
Correct:
select
case
when clf.last_milestone='APPROVED' THEN clf.application_received_and_approved_at
when clf.last_milestone='LOCK' THEN clf.locked_at
when clf.last_milestone='FUNDING' THEN clf.funded_at
end as Last_Milestone_at
from
core.loan_file_milestone_days as clf
Solution 2:[2]
select clf.loan_file_id,cld.last_milestone,
case cld.last_milestone
when 'APPROVED' THEN clf.application_received_and_approved_at
when 'LOCK' THEN clf.locked_at
when 'FUNDING' THEN clf.funded_at
end as Last_Milestone_at
from
core.loan_files as clf
inner join
core.loan_file_milestone_days as cld
using(loan_file_id)
THIS IS THE SOLVED ONE THANK YOU GUYS Instead of using cld.last_milestone in condition again and again just go with case cld.milestone when condition then... when condition then... end as
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
