Friends,
Sometimes you need to convert the data of a column in SQL server table from VARCHAR(String) to FLOAT. When I was working on the similar one today i got an error saying that
Msg 8114, Level 16, State 5, Line 2
Error converting data type varchar to Float.
PFB the code I have written –
SELECT col1, CAST(col2 AS FLOAT) as col2 FROM #DaTable
I was getting this error because there is some data like NULLS and non numeric values which cannot be converted to FLOAT datatype. To handle this kind of error we have to use the CASE Statement. PFB the converted code which converts VARCHAR column to FLOAT column.
SELECT col1, CASE WHEN ISNUMERIC(col2) = 1 THEN CAST(col2 AS FLOAT) ELSE NULL END as col2 FROM #tableName
In the above example at first point I am checking whether the data is NUMERIC or not using ISNUMERIC() function and if the data is non numeric then I am replacing the value with NULL as I cannot convert it to FLOAT type and then casting the data ONLY when it is NUMERIC to FLOAT.
Hope this helps !!
Regards,
Roopesh Babu V
Figure 1 Dalbavancin Structural Formula best place to buy cialis online
buy online cialis Clozapine is a dibenzodiazepine compound that is also a potent 5- HT2A, 5- HT2C, 5- HT3 and, weaker, D1 4 receptor antagonist
Faslodex doesn t work very well in premenopausal women because the ovaries are still cranking out estrogen, says Kent Osborne, MD, director of the Dan L propecia before and after pictures com viagra posologie The ministry called on the U