0

Have a ncarchar(MAX) field in SQL table. It has numbers such as 717.08064182582, 39.0676048113, etc. in which I need to only have 3 places after decimal. For instance 717.080, 39.067.

Without converting the field type, would like to get rid of those last n characters, however every row has different number of characters. I believe I could use ROUND (correct me if wrong), but would rather not.

3 Answers3

1

Try this

SELECT CAST(ColumnName AS DECIMAL(18,3))

Without converting it data type As per @vkp Comment

SELECT SUBSTRING(ColumnName ,0,CHARINDEX('.', ColumnName )+4)
Jaydip Jadhav
  • 12,179
  • 6
  • 24
  • 40
1
select  CASE    WHEN    CHARINDEX('.', Your_column) > 0 
                THEN    SUBSTRING(Your_column, 1, CHARINDEX('.', Your_column) + 3)
                ELSE    Your_column
        END

this is similar as previous answers but more faster and safer

Alexey
  • 31
  • 4
0

Try this:

SELECT  SUBSTRING(Your_column, 1, PATINDEX('%.%', Your_column) + 3)
FROM    Your_Table
HoneyBadger
  • 14,750
  • 3
  • 34
  • 48