on 2012 Feb 14 9:38 AM
Hi There, I have an SQL problem I hope someone would be able to assist.
I need to covert a number to string with a specific format, i.e. not ending up the number with .0000 which doesn't make sense. Is there any function in SQL Anywhere that gets a number and a format mask and produces the required string?
Another one, regarding alternative to NVL function of Oracle. If I use the nullif in Strings, I still get the result as number which then get's converted. Any ideas how to prevent that?
Thanks, Dvir
Request clarification before answering.
AFAIK, there's no such general "number-formatting function" (though it has been requested in the past...). However, there are some general data conversion functions like STR or CAST (or conversions to numerical data with fixed number of decimal places) that may be helpful in simple cases, such as
select str(6.1234), cast(6.1234567890 as varchar), cast(cast(6.1234567890 as numeric(10,2)) as varchar)
returns
6, 6.123456789, 6.12
The following FAQ may help further:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the convert function will take a number and convert it to text. select convert( char( 20 ), 12345.6789 ) from table will convert the number to text but will not format it to 12,345.6789
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
52 | |
8 | |
5 | |
5 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.