0

I wish to write a query which will replace the value0.00 with "-" in a column. The value should only be replaced if the value is 0.00 and not if 230.00

I did this query replace(SUBSTRING(cast(columname AS varchar(7)),0,7),'0.00','-') but it replaces 230.00 as 23-

Please help

0

3 Answers 3

2

Assuming a table format like so:

`id` | `cost`
 1   | 230.00
 2   | 543.65
 3   | 0.00

Then a query of

SELECT CASE WHEN cost=0 THEN '-' ELSE cost END FROM table;

will return

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

Comments

0

use:

if (SUBSTRING(cast(columname AS varchar(7)),0,7) = '0.00', '-', SUBSTRING(cast(columname AS varchar(7)),0,7))

Comments

0

CASE WHEN columname = 0 THEN '0.00' ELSE replace(SUBSTRING(cast(columname AS varchar(7)),0,7),'0.00','-') END

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.