Is there a way I can convert a numeric, with scale, to a string with leading and trailing zeros stripped ? I've looked at the CAST and CONVERT documentation, but cannot find a mask to apply to a numeric. In PostgreSQL and Oracle I simply apply a format mask, the same mask works for both, like so:
|
If you use Oracle's TO_CHAR with the format model feature a lot, perhaps you should implement your own version of (a subset of?) TO_CHAR as a SQL Anywhere CREATE FUNCTION. Otherwise, here is a combination of SQL Anywhere's STRING(), REPLACE() and TRIM() functions that (a) changes all zeros to spaces, (b) removes leading and trailing spaces, then (c) changes all surviving spaces back to zeros... ( Caveat Emptor: The testing you see is the testing that was performed :) CREATE TABLE T3 ( E NUMERIC(4,4) ); INSERT T3 VALUES (.1), (.2), (.3), (.4), (.501), (.6101); COMMIT; SELECT E, REPLACE ( TRIM ( REPLACE ( STRING ( E ), '0', ' ' ) ), ' ', '0' ) AS E_STR FROM T3 ORDER BY E; E,E_STR 0.1000,.1 0.2000,.2 0.3000,.3 0.4000,.4 0.5010,.501 0.6101,.6101 |
I think this is somewhat of a solution, although it seems convoluted,
Any suggestions for alternatives maybe ?