View Single Post
  #20 (permalink)  
Old 08-07-09, 17:09
javaguru javaguru is offline
Registered User
 
Join Date: Aug 2009
Posts: 1
concat the integer and the fractional portion of the value

The best solution I figured out on how to remove leading zeros when converting Decimal to Char/Varchar in SQL is to concat the integer and the fractional portion of the value as shown in the following (standalone) example:

select concat(concat(rtrim(char(int(val))), '.'),
rtrim(right(char(val - int(val)), 3)))
from (values (10.20), (11), (.02), (.3), (123)) as mytab(val);


1
------
10.20
11.00
0.02
0.30
123.00

5 record(s) selected [Fetch MetaData: 0/ms] [Fetch Data: 0/ms]

cheers
javaguru
Reply With Quote