I am using a view with a column that contains a varchar which can have a value like 8.60 or V or NULL.
And I am trying to create a select statement which casts the value as numeric when it is possible or else return the original value.
So I came up with this test query:
SELECT
CASE
WHEN ISNUMERIC('V') = 1
THEN cast(round('V', 1) as numeric(4,1))
ELSE 'V'
END
as Value;
And I expect it to return V, but I am getting an error: Error converting data type varchar to numeric.
I have tried playing around with TRY_PARSE and TRY_CAST and with the round and cast with no success. The error seems to be with the THEN clause, because without, it does not throw an error.
How should I write this query?
SQL version: Microsoft SQL Server 2014 (SP2-GDR) (KB4019093) - 12.0.5207.0 (X64)
Using: Microsoft SQL Server Management Studio v12.0.2000.8