all groups > sql server mseq > november 2005 >
You're in the

sql server mseq

group:

No Decimal trailing sign



No Decimal trailing sign Stan
11/3/2005 5:49:12 AM
sql server mseq: 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-.

--
Re: No Decimal trailing sign Steve Kass
11/3/2005 11:52:08 AM
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

[quoted text, click to view]
AddThis Social Bookmark Button