select left(replace(cast(mycolumn as varchar(20)),'.','') + '00000', 5) as n
from mytable
how to convert the decimal value into number in sql server
Naresh y
146
Reputation points
Hi team.
i have a table where i can convert to decimal to number. and to restrict the length to 5 places
Source values
12.09870
156.98655
23.099878
Desired list
120987
15698
23099
I am trying to load this data into notepad file, the length is not restricting to 5 places while generating the file
2 answers
Sort by: Most helpful
-
Bruce (SqlWork.com) 69,976 Reputation points
2023-05-08T16:20:17.5566667+00:00 -
ZoeHui-MSFT 40,051 Reputation points
2023-05-09T02:35:36.31+00:00 Hi @Naresh y,
You may add Derived Column with below expression to do that.
LEFT(((DT_WSTR,50)(yourcolumn * 10000)),5)
Regards,
Zoe Hui
If the answer is helpful, please click "Accept Answer" and upvote it.