Change type of a column with numbers from varchar to int

The only reliable way to do this will be using a temporary table, but it will not be much SQL:

select * into #tmp from bad_table
truncate table bad_table
alter bad_table alter column silly_column int
insert bad_table
select cast(silly_column as int), other_columns
from #tmp
drop table #tmp

The easiest way to do this is:

alter table myTable alter column vColumn int;

This will work as long as

  1. all of the data will fit inside an int
  2. all of the data can be converted to int (i.e. a value of "car" will fail)
  3. there are no indexes that include vColumn. If there are indexes, you will need to include a drop and create for them to get back to where you were.