[thelist] SQL Server: How Can I Convert VARCHAR to INT?

James Aylard webmaster at equilon-mrc.com
Thu Aug 16 11:02:13 CDT 2001


SQL Gurus:

    I've got a MS SQL Server 7 database table with some columns that contain
varchar data. The intended use of these particular fields is to contain
numeric data (and most of them do contain numeric data or are null), so we
want to switch the data type from varchar to int. But some of them contain
non-numeric data (which is unneeded and can be discarded), which prevents a
simple switch of the data type.
    Is there a straightforward way to convert a varchar column to an int
column, short of manually editing the offending data? CAST throws an error
when it hits a field that contains non-numeric data or isn't null (which you
already knew, I'm sure).
    Any help would be appreciated. Thanks.

James Aylard





More information about the thelist mailing list