Reputation: 11
I get an error 'syntax error in from clause' when I try to run my case when:
select ewc_code, shortclass as EWCDesc, tonnage as tonnes,
waste_fate as fate, 'deposit wpa' as destination
from hwi
CASE waste_fate
WHEN 'Transfer (r)' THEN 'Transfer'
When 'Transfer (d)' then 'transfer'
else waste_fate
Upvotes: 0
Views: 114
Reputation: 7009
You were missing an END
:
CASE WHEN waste_fate = 'Transfer (r)' THEN 'Transfer'
WHEN waste_fate = 'Transfer (d)' THEN 'transfer'
ELSE waste_fate END
And this returns a scalar that you need to think what do you want to do with.
Most chances is, that you wanted to add it to your SELECT
clause and not your FROM
clause.
Upvotes: 0
Reputation: 43464
Firstly, the CASE
should be inside your query, most likely in the SELECT
clause.
Secondly you are missing the END
in your CASE
statement:
SELECT ewc_code, shortclass as EWCDesc, tonnage as tonnes, waste_fate as fate,
'deposit wpa' as destination,
CASE waste_fate
WHEN 'Transfer (r)' THEN 'Transfer'
WHEN 'Transfer (d)' THEN 'transfer'
ELSE waste_fate
END
FROM hwi
Upvotes: 1