-
Formatting decimal values as string
Hi,
I wonder what the most elegant approach to the following task might be. I
tried with substring, convert, floor and other functions, but that all seems
to complicated. There must be another way.
I want to format a decimal(9,2) value to a right justified string with a
decimal sign ',' and leading characters.
For example:
17.1 should result in '-----17,10'
673.78 should result in '----673,78'
1.00 should result in '------1,00'
TIA, Norbert Meiss
-
Re: Formatting decimal values as string
This type of formatting should be done on the client/reporting
interface. Here is one way in T-SQL:
SELECT REPLACE(REPLACE(STR(n, 10, 2), ' ', '-'), '.', ',')
FROM (SELECT 17.1
UNION
SELECT 673.78
UNION
SELECT 1.00) AS T(n);
--
Plamen Ratchev
http://www.SQLStudio.com
-
Re: Formatting decimal values as string
>> I want to format a decimal(9,2) value to a right justified string with a decimal sign ',' and leading characters. <<
SQL is an abstract language and does not have support for such display
formatting.
Good programmers format data in the front end. Look at the PICTURE
clause in COBOL, or "###.##" templates in various version of BASIC,
etc.
-
Re: Formatting decimal values as string
And what does a good programmer in the case he has to present the formatted
figure as nth column in a listbox (Access)?
"--CELKO--" wrote:
> >> I want to format a decimal(9,2) value to a right justified string with a decimal sign ',' and leading characters. <<
>
> SQL is an abstract language and does not have support for such display
> formatting.
> Good programmers format data in the front end. Look at the PICTURE
> clause in COBOL, or "###.##" templates in various version of BASIC,
> etc.
>
-
Re: Formatting decimal values as string
>> And what does a good programmer in the case he has to present the formatted figure as nth column in a listbox (Access)? <<
Good programmers don't use ACCESS and SQL has no "listbox" :) You
use whatever you have in your front end product. YOu are not in
"desktop land" any more.
Desktop, single user products like ACCESS, Filemaker Pro, Alpha
Five, Paradox or Lotus Approach are fine for that they are, but they
are not in the same class as SQL Server, which is not in the same
class as DB2, Oracle, et al, which are not Teradata, SAND, WX2, et
al.
-
Re: Formatting decimal values as string
On Aug 26, 10:34*am, --CELKO-- wrote:
> >> And what does a good programmer in the case he has to present the formatted *figure as nth column in a listbox (Access)? <<
>
> Good programmers don't use ACCESS and SQL has no "listbox" :) * You
> use whatever you have in your front end product. *YOu are not in
> "desktop land" any more.
>
> Desktop, single user products like ACCESS, Filemaker Pro, *AlphaFive, *Paradox or Lotus Approach are fine for that they are, but they
> are not in the same class as SQL Server, which is not in the same
> class as DB2, Oracle, et al, which are not Teradata, SAND, WX2, et
> al.
A point of clarification
Alpha Five is really a RAD - rapid application development- tool for
building custom applications (desktop or AJAX powered web) against
its built in database engine OR against SQL backends such as MS SQL
server, Oracle,. DB2, Postgres, Quickbooks, MySQL or even Excel or MS
Access tables. More info is at www.alphasoftware.com