I have the below select stmts but I get an error message when i try to combine them. I want to convert diag_1 varchar datatype for example 250.8 to an integer and then round down to the nearest full number eg 250.
Also the data contains values with V25 aswell as numeric. Is it possible to remove the 'V' from some of the data?
Select encounter_id,diag_1,diag_2,diag_3,
Try_convert(float,[diag_1]) as [float1],
Try_convert(float,[diag_2]) as [float2],
Try_convert(float,[diag_3]) as [float3]
from dbo.encounters;
Select round(float1,1) as roundvalue
from dbo.encounters;
Best Answer
Lots going on here. Why are you storing numbers in a
varchar
column? Why do you sometimes have a number that's only kind of a number? You can fix some of these complications of course by cleaning the data before inserting it and using the right data type. In the meantime, something like this is ugly but gets the job done.Results: