Wednesday, March 28, 2012

question regarding putting commas in between a no

How do i put commas so 1234567

comes out as 1,234,567

i know how to put $ in front but i cant figure out how to put commas in the middle of a no. Can anybody help?

i am new at all of this. Sad

SQL Server is not very fast at string manipulation. You're better off doing that in your managed code (i.e. your data access layer, or, preferably, in your UI layer).|||

I agree with robert about formating the ouput in the UI layer. But if you insist, then see function "convert" in BOL.

selectreverse(stuff(reverse(convert(char(25),cast(1234567 asmoney), 1)), 1, 3,''))

AMB

|||

If you are attempting to format currency, try this:


Code Snippet


SELECT ( '$' + convert( varchar(25), cast( 1234567 AS money ), 1 ))


--
$1,234,567.00

No comments:

Post a Comment