I want to remove trailing zeros from the results produced by stored procedure.
SELECT rdts_SizeIN
FROM CatalogSQL.dbo.RuptureDiskTypeSize
WHERE [rdts_RuptureDiskTypeID]=@rdts_RuptureDiskTypeID and rdts_Active
=@Active
rdts_SizeIN is a decimal field in the table.
Resulting data maybe:
0.2500
0.5000
1.0000
1.5000
2.0000
3.0000
I want it to look like:
0.25
0.5
1
1.5
2
3
Can some one help
CREATE FUNCTION dbo.fn_removetrailingchars
(
@strValue VARCHAR(200),
@TrailingChar VARCHAR(200),
@RemoveLeading BIT
)
RETURNS VARCHAR(200)
AS
BEGIN
DECLARE @intCount int
SET @intCount = 0
WHILE @intCount <= LEN(@strValue)
BEGIN
SET @intCount = @intCount +1
IF SUBSTRING(@strValue, @intCount, 1) NOT LIKE @TrailingChar
BREAK
ELSE
CONTINUE
END
IF @RemoveLeading = 1
SET @strValue =
REVERSE(dbo.fn_removetrailingchars_drkw(REVERSE(RIGHT(@strValue,
LEN(@strValue) - @intCount +1 )),@TrailingChar,0))
ELSE
SET @strValue = RIGHT(@strValue, LEN(@strValue) - @intCount +1
)
RETURN @strValue
END
Lets me know if that helps,
HTH, jens Suessmeyer.
ML
--
William Stacey [MVP]
"kafi" <ka...@discussions.microsoft.com> wrote in message
news:E24D4944-9DD3-4053...@microsoft.com...
select
replace(rtrim(replace(replace(rtrim(replace(convert(varchar,testdata),'0','
')),' ','0'),'.',' ')),' ','.')
from testdecimals
probably better ways out there from some of the MVP's
--
William Stacey [MVP]
"kafi" <ka...@discussions.microsoft.com> wrote in message
news:1D08BCD9-635A-46D7...@microsoft.com...
you will need to do another replace for the decimal point at the end
instead of this
select replace(rtrim(replace('10305.00000','0',' ')),' ','0')
it has to be this
select
replace(rtrim(replace(replace(rtrim(replace(convert(varchar,'10305.00000'),'0','
')),' ','0'),'.',' ')),' ','.')