Forum Discussion
Converting a varchar field to Numeric
Hi RayMilhon -- To find only records having numeric data, you can use the isnumeric function. A simple example of its use is shown below.
https://docs.microsoft.com/en-us/sql/t-sql/functions/isnumeric-transact-sql?view=sql-server-ver16
select * from aTable where isnumeric(colone) = 1
But if I'm understanding correctly, it seems like you want to convert the existing column from char to numeric. The only way that you can do that is to first delete all records with non-numeric data in the existing char column. Otherwise, you ALTER TABLE statement will fail.
Another alternative would be to create a new numeric column, hydrate it with numeric-only data from the existing char column (using the isnumeric function), then rename the old column and new columns so existing queries, stored procedures, views, etc. are not broken. Take care.