Shaun Mccran

My digital playground

24
J
U
L
2008

SQL Formatting a numeric field to 2 decimal places

Need to format a field to a certain number of decimal places?

Just do this:

view plain print about
1CAST([itemTotal] AS decimal(8,2)) AS [total]

So a full query would look like:

view plain print about
1Select field1,
2field2,
3field3,
4CAST([itemTotal] AS decimal(8,2)) AS [total],
5field4
6from dbo.table

This will supply you with the field 'Total' in an 'xx.xx' format.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Back to top