How can I format the number 123.45678 to 123.45 in SQL Server 2008?
+1
A:
You can declare the item as decimal(10,2) and then do a select on that item
e.g. f decimal(8, 2)
AutomatedTester
2009-08-08 13:12:57
+4
A:
Casting to a decimal (10,2)
as suggested by the current answers will work, if you're happy to round to 123.46.
However if you want a truncation (as you seem to imply in your provided example) then you might want to apply the ROUND function first:
SELECT CAST(ROUND(123.45678, 2, 1) AS DECIMAL(9,2))
---------------------------------------
123.45
You can also use the ROUND function to produce actual rounding, but it's functionally identical to doing the cast alone, though maybe slightly clearer in intention.
SELECT CAST(ROUND(123.45678, 2) AS DECIMAL(9,2))
---------------------------------------
123.46
Gavin Schultz-Ohkubo
2009-08-08 14:03:40