Monday, March 26, 2012

No Decimal trailing sign

I have a field defined as (decimal 9(15,2)) and the recipient of a conversion
..txt file wants to see just the meaningful digits, no decimals, no zero fill
but does want to
see a trailing minus sign for negative numbers. So they want to see 550.45
as 55045 and -45.25 as 4525-.
Stan Gosselin
Stan,
You'll have to use string functions to do this.
Here's one solution:
declare @.t table (
d decimal(15,2)
)
insert into @.t values (550.45)
insert into @.t values (10000)
insert into @.t values (-45.25)
insert into @.t values (0)
insert into @.t values (0.01)
insert into @.t values (1)
select
case when d >= 0
then ltrim(cast(100*d as int))
else ltrim(cast(-100*d as int)) + '-' end
from @.t
Be sure you and the client agree on how to represent everything.
This solution represents 0 as '0', not '000', for example, which may
or may not be right.
Steve Kass
Drew University
Stan wrote:

>I have a field defined as (decimal 9(15,2)) and the recipient of a conversion
>.txt file wants to see just the meaningful digits, no decimals, no zero fill
>but does want to
>see a trailing minus sign for negative numbers. So they want to see 550.45
>as 55045 and -45.25 as 4525-.
>
>
sql

No comments:

Post a Comment