sqlsql-servert-sql

SQL Server : convert char to float and round it


I have a database with a column of VARCHAR2 type keeping a value like: 398566,569885

What I need is to cast this number to float and then to make it looking like: 398566,56 Casting it to float is not so important, if It's possible to trim the numbers it will be also ok.

What I have tried is:

select
cast (p1.VALUE as float) as Total
from Workflow p
LEFT JOIN PA_PARAMETER p1 on p1.ID=p.ID AND p1.NAME = 'Total'
WHERE p.TYPE = 'Marketing'

Is there a way to trim these numbers or to round it somehow?


Solution

  • This will round your numbers

    select cast(value as decimal(9,2)) 
    from workflow...