0

I am getting the error

syntax error at or near "where" LINE 5: where zip in (select zipcode from zips where city = 'Sacra

when I try to run this code.

update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100)))
where zip in (select zipcode from zips where city = 'Sacramento');

Does anybody see any easy to fix errors? or did I come up with some garbage code?

2
  • You don't need the case, as you have no else part. Just add price is not null to your where clause and you can get rid of the whole CASE and make the update even more efficient. Commented Apr 7, 2015 at 7:05
  • just see the updated answer @a_horse_with_no_name suggestion is added :) Commented Apr 7, 2015 at 7:24

3 Answers 3

1

An SQL CASE expression needs to be ended with END keyword.

Sign up to request clarification or add additional context in comments.

Comments

0

Add an end keyword just before where clause

update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100))) END
where zip in (select zipcode from zips where city = 'Sacramento');

As per @a_horse_with_no_name's Comment

update listings 
set price = (price * (((100+(select price_change from zips where zips.zipcode=listings.zip))/100))) 
where zip in (select zipcode from zips where city = 'Sacramento') and listings.price IS NOT NULL

Comments

0
update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100)))
where zip in (select zipcode from zips where city = 'Sacramento')

remove ; try again

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.