In SQL when you convert anything to a decimal you have to provide the number of decimal places as part of the conversation. For example
DECLARE @NumberAsString VARCHAR(20)
SET @NumberAsString = '1038.93801'
DECLARE @NumberAsDecimal DECIMAL(28.10)
SET @NumberAsDecimal = CONVERT(DECIMAL(28,10), @NumberAsString)
If you execute SELECT @NumberAsDecimal what you get back is '1038.9380100000'. The reason why the result is padded with zeros is because the number of decimal places specified during the conversion is 10. Such a result can look very ugly in reports.
In SQL server 2005 there is no easy way to get rid of extra zeros. The fastest and simplest way I know is the following
CREATE FUNCTION GetNonPaddedDecimal
(
@number Decimal(38,10)
)
RETURNS VARCHAR(max)
AS BEGIN
RETURN REPLACE(RTRIM(REPLACE(REPLACE(RTRIM(REPLACE(@number, '0', ' ')), ' ', '0'), '.', ' ')), ' ', '.')
END
Thanks to Ashar for coming up with it