sql - A more concise way to format COUNT result with thousands separator? -


goal

format count result common format (e.g. ###,##0) in concise statement , without udf's.

i've tried

i using this, though leaves 2 decimals and clunky:

select convert(varchar, cast(count([id]) money), 1) tbl 

the reason went direction because standard formatting option find when reading through cast , convert documentation msdn.

i don't it, limps along since these numbers copied , pasted other text editors , such after t-sql runs. of course have formatted hand remove decimals in places.

research , restrictions

of course build user-defined function, one on blog, have restriction keeps me building udf's purpose.

after additional research found if using sql 2012 use new t-sql format function, alas, i'm restricted 2008 r2. of course leverages different platform it's .net interface. :d

i aware of solution: format number commas without decimals in sql server 2008 r2?

not elegant, can remove trailing .00 replace.

select replace(convert(varchar, cast(count([id]) money), 1), '.00', '') tbl 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -