Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi - I have a number in my database stored as an INT that looks like 14755.25676200. However I want it to look like 14,755.26 but cannot get the convert function to work. Can anyone help me?
lionofdezert
Aged Yak Warrior
885 Posts
Posted - 2011-04-19 : 11:11:20
INT cann't containt value like 14755.25676200Possibly u need thisDECLARE @TEST FLOATSET @TEST =14755.25676200SELECT CONVERT(VARCHAR,CONVERT(MONEY, @TEST),1)
jcb267
Constraint Violating Yak Guru
291 Posts
Posted - 2011-04-19 : 11:15:03
sorry about that, it is a decimal......
quote:Originally posted by lionofdezert INT cann't containt value like 14755.25676200stillDECLARE @TEST FLOATSET @TEST =14755.25676200SELECT ROUND(@TEST,2)--------------------------http://connectsql.blogspot.com/
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2011-04-19 : 11:31:22
Formatting should be done in the front end. However, do you want to round or truncate?
DECLARE @N NUMERIC(13,8) = 14755.25676200SELECT CAST(ROUND(@N, 2, 0) AS NUMERIC(13, 2)), CAST(ROUND(@N, 2, 1) AS NUMERIC(13, 2)), CONVERT(VARCHAR(13), CAST(ROUND(@N, 2, 0) AS MONEY), 1), CONVERT(VARCHAR(13), CAST(ROUND(@N, 2, 1) AS MONEY), 1)