1

I’m running a query from a table that has info on account numbers, settled charges , the write off figure, and the reason for the write off; so the table is called group_write_off and the table headings, account_id, charge_settled_date, total_charge_amount, amount_written_off, write_off_reason. What I want to do, is pull everything through, so

Select * from group_write_off

but for any case where the write_off_reason includes the word ‘Audit’, I want amount_written_off to show as 0 (zero), for all others i want the original amount_written_off to show.

Many thanks.

1 Answer 1

5

Use CASE expression.

SELECT CASE WHEN write_off_reason='Audit' THEN 0 ELSE amount_written_off END
FROM group_write_off

Also try below for checking if Audit word is present in column write_off_reason by using INSTR() function

SELECT CASE WHEN INSTR(write_off_reason,'Audit') = 0 THEN 0 ELSE amount_written_off END
FROM group_write_off

If you want more words

SELECT CASE WHEN INSTR(write_off_reason,'Audit') = 0 THEN 0 
       WHEN INSTR(write_off_reason,'admin') = 0 THEN 0 
       ELSE amount_written_off END
FROM group_write_off
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent, many thanks. If i wish to include additional write_off reasons, for instance any write_off_reason which includes the word 'admin', how would I insert this into the code above?

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.