Reputation: 842
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
Upvotes: 0
Views: 1588
Reputation: 10341
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
-
Upvotes: 2
Reputation: 1406
CASE WHEN columname = 0 THEN '0.00' ELSE replace(SUBSTRING(cast(columname AS varchar(7)),0,7),'0.00','-') END
Upvotes: 0
Reputation: 730
use:
if (SUBSTRING(cast(columname AS varchar(7)),0,7) = '0.00', '-', SUBSTRING(cast(columname AS varchar(7)),0,7))
Upvotes: 0