Subject | Re: [firebird-support] zeros of a field decimal |
---|---|
Author | Ismael L. Donis García |
Post date | 2009-05-26T15:22:20Z |
Thanks.
At present I use, but I find it somewhat ugly. I wanted to know if show existed for that.
SELECT iif(right(a.cantidad, 1)='0',
iif(right(a.cantidad, 2)='00',
iif(right(a.cantidad, 3)='000',
iif(right(a.cantidad, 4)='0000',
left(a.cantidad, character_length(a.cantidad)-5),
left(a.cantidad, character_length(a.cantidad)-3)),
left(a.cantidad, character_length(a.cantidad)-2)),
left(a.cantidad, character_length(a.cantidad)-1)), a.cantidad)
FROM tabla a
=========
¦¦ ISMAEL ¦¦
=========
----- Mensaje original -----
De: Svein Erling Tysvær
Para: firebird-support@yahoogroups.com
Enviado: martes, 26 de mayo de 2009 02:01
Asunto: RE: [firebird-support] zeros of a field decimal
I've at least never heard of such a function, and generally think that how things are displayed is something for client programs to decide rather than a database server. Though, it is of course possible, at least for display purposes, to fake such an algorithm. Assuming the number is a fixed decimal (floating point decimals are something completely different) with a value less than 10:
SELECT
CASE WHEN MyValue = cast(MyValue as Integer) then cast(MyValue as CHAR(1))
WHEN MyValue = cast(MyValue*10 as Integer)/10.0 then cast(MyValue as CHAR(3))
WHEN MyValue = cast(MyValue*100 as Integer)/100.00 then cast(MyValue as CHAR(4))
WHEN MyValue = cast(MyValue*1000 as Integer)/1000.000 then cast(MyValue as CHAR(5))
WHEN MyValue = cast(MyValue*10000 as Integer)/10000.0000 then cast(MyValue as CHAR(6))
END
...
I haven't tried this, if Firebird complains, then add a few spaces (||' ', ||' ', ||' ', ||' ' respectively) to the result so that they're all equally long.
HTH,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Ismael L. Donis García
Sent: 25. mai 2009 18:28
To: firebird-support@yahoogroups.com
Subject: [firebird-support] zeros of a field decimal
Exists any function that returns the value without zeros of a field decimal.
Example:
select function(a.cantidad) as cantidad from tabla a
Value Result
3.0000 3
3.0100 3.01
3.0210 3.021
3.0004 3.0004
Thanks and Excuse the simplicity of the question but I do not find anything than accomplish such operation.
=========
¦¦ ISMAEL ¦¦
=========
[Non-text portions of this message have been removed]
At present I use, but I find it somewhat ugly. I wanted to know if show existed for that.
SELECT iif(right(a.cantidad, 1)='0',
iif(right(a.cantidad, 2)='00',
iif(right(a.cantidad, 3)='000',
iif(right(a.cantidad, 4)='0000',
left(a.cantidad, character_length(a.cantidad)-5),
left(a.cantidad, character_length(a.cantidad)-3)),
left(a.cantidad, character_length(a.cantidad)-2)),
left(a.cantidad, character_length(a.cantidad)-1)), a.cantidad)
FROM tabla a
=========
¦¦ ISMAEL ¦¦
=========
----- Mensaje original -----
De: Svein Erling Tysvær
Para: firebird-support@yahoogroups.com
Enviado: martes, 26 de mayo de 2009 02:01
Asunto: RE: [firebird-support] zeros of a field decimal
I've at least never heard of such a function, and generally think that how things are displayed is something for client programs to decide rather than a database server. Though, it is of course possible, at least for display purposes, to fake such an algorithm. Assuming the number is a fixed decimal (floating point decimals are something completely different) with a value less than 10:
SELECT
CASE WHEN MyValue = cast(MyValue as Integer) then cast(MyValue as CHAR(1))
WHEN MyValue = cast(MyValue*10 as Integer)/10.0 then cast(MyValue as CHAR(3))
WHEN MyValue = cast(MyValue*100 as Integer)/100.00 then cast(MyValue as CHAR(4))
WHEN MyValue = cast(MyValue*1000 as Integer)/1000.000 then cast(MyValue as CHAR(5))
WHEN MyValue = cast(MyValue*10000 as Integer)/10000.0000 then cast(MyValue as CHAR(6))
END
...
I haven't tried this, if Firebird complains, then add a few spaces (||' ', ||' ', ||' ', ||' ' respectively) to the result so that they're all equally long.
HTH,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Ismael L. Donis García
Sent: 25. mai 2009 18:28
To: firebird-support@yahoogroups.com
Subject: [firebird-support] zeros of a field decimal
Exists any function that returns the value without zeros of a field decimal.
Example:
select function(a.cantidad) as cantidad from tabla a
Value Result
3.0000 3
3.0100 3.01
3.0210 3.021
3.0004 3.0004
Thanks and Excuse the simplicity of the question but I do not find anything than accomplish such operation.
=========
¦¦ ISMAEL ¦¦
=========
[Non-text portions of this message have been removed]