T-SQL format 10000 as 10,000

In the following code I am able to add comas using CAST(... money) but it comes with trailing .00

Question: How can I get rid of these trailing .00?

I have tried:

REPLACE(CONVERT(varchar(20), (CAST(SUM(table.value) AS money)), 1), '.00', '')

but, maybe this is dynamic sql, the highlighted portion above produces error. (Incorrect syntax near '.00').

Thank you.
	SELECT @nsql = 'SELECT t.LastYearCount  as [' + @LY + '], 
	CONVERT(varchar(20), (CAST(t.CurrYearCount AS money)), 1)  as [' + @YYYY + '], 
	convert(varchar,convert(decimal(8,1),(t.IncreaseOverLastYear/100))) as [%]  
	FROM t14StatType AS s INNER JOIN (t08MedCenter AS m INNER JOIN t10YearlyCount AS t 
	ON m.MedCtrID = t.MedCtr_ID) ON s.StatTypeID = t.StatType_ID 
	WHERE (((s.StatTypeID)=' + CONVERT(varchar(100),@StatType_ID) + ') AND ((t.YYYY)=' + @YYYY + ') AND ((m.ExcludeYN)=0) 
	   AND ((t.Region_ID)=' + CONVERT(varchar(100),@RegionID) + ')) ORDER BY m.Sort;' 

    EXEC (@nsql)

Open in new window

LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

which version of SQL Server is this for please? (or, which versions)
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
2008 r2
mmm, see is STR() or FLOOR() help perhaps?

declare @m as money = 10000.12

select @m, str(@m,8,0), floor(@m)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mmm(2), see is STR() or FLOOR()or ROUND  help perhaps?

declare @m as money = 10000.12

select @m, str(@m,8,0), floor(@m), round(@m,0)
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
replace(convert(varchar(20),CAST(t.LastYearCount  AS money), 1),''.00'','''')

I had to double single quotes.
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.