July 20, 2011 at 1:27 pm
I have numbers as text without thousand separator. Now I need to add comma as a thousand separator to this text number. How can I do this?
July 20, 2011 at 1:43 pm
check out Cast and Convert in Books online:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
if your original datatype is money, then one of the overloaded parameters of the CONVERT function is to insert the commas like you describe.
--resulkts = 1,234,567.89
with MySampleData as
(
select convert(money,1234567.8910)As TheVal
)
select convert(varchar,TheVal,1) --1 means Commas every three digits to the left of the decimal point, and two digits to the right of the decimal point; for example, 3,510.92.
from MySampleData
in order for you to use tthat function, you'll need to go thru the extra step of converting your text value to money, and then using the convert function back to varchar, but make sure you include the optional second parameter.
Lowell
July 21, 2011 at 6:03 pm
Is this also supported in SQL Server 2005?
Lowell (7/20/2011)
check out Cast and Convert in Books online:http://msdn.microsoft.com/en-us/library/ms187928.aspx
if your original datatype is money, then one of the overloaded parameters of the CONVERT function is to insert the commas like you describe.
--resulkts = 1,234,567.89
with MySampleData as
(
select convert(money,1234567.8910)As TheVal
)
select convert(varchar,TheVal,1) --1 means Commas every three digits to the left of the decimal point, and two digits to the right of the decimal point; for example, 3,510.92.
from MySampleData
in order for you to use tthat function, you'll need to go thru the extra step of converting your text value to money, and then using the convert function back to varchar, but make sure you include the optional second parameter.
July 21, 2011 at 7:57 pm
Yes. But, since you're in the "Newbie" forum, I have to tell you that ...
1) Formatted data should not be permanently stored in SQL Server, period.
2) SQL Server should usually not be used for formatting. Do it in the GUI or reporting too, instead.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 20, 2011 at 6:29 pm
select CONVERT(varchar, CAST(valor_avaluo_catastral as money), 1) from dbo.solicitud_permutas
Only need convert your numeric field in money cast(numeric_atribute as money) ... then convert this result to varchar with CONVERT function with 1 like parameter ... Thanks
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply