I have an nvarchar column that is sometimes used to hold numeric data and I wish to pull that data out as real and changing text values to zero. So I wrote a query something like the following:
I am getting an error that states: Error converting data type nvarchar to real. I am finding that ISNUMERIC(TextField)=1 is still allowing commas, dashes by themselves, and who knows what else. For example: 1,5 and -. These apparently "numeric" values can't be converted to real. Can anyone tell me a test that is more conclusive than ISNUMERIC? I wish there was an ISREAL function...
Thank you!
Code:
SELECT CASE WHEN ISNUMERIC(TextField)=1 THEN CAST(TextField AS real) ELSE 0 END
FROM MyTable
Thank you!