0

I have a column with values '< 500' and '> 500' in several hundred rows. Those are the only two figures. Now, I want to replace all '< 500' with 'xx' and all '> 500' with 'yy'.

Is there any way to replace both the values in a single SQL query rather than using two separate update queries as below:

UPDATE [table] SET [column] = 'xx' WHERE [column] = '< 500';
UPDATE [table] SET [column] = 'yy' WHERE [column] = '> 500';

I tried using Case for this, but couldn't get it working.

1
  • Your syntax suggests SQL Server so I removed the oracle tag. Commented Apr 22, 2016 at 2:49

1 Answer 1

3

Yes, use a case statement:

UPDATE [table]
    SET [column] = (CASE WHEN [column] = '< 500' THEN 'xx' ELSE 'yy' END)
    WHERE [column] IN ('< 500', '> 500');
Sign up to request clarification or add additional context in comments.

1 Comment

You type faster than me @Gordon :)

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.