Convert INT to VARCHAR
sql-server-2008
Solution
alter table Table1
alter column SSN varchar(9);
You can do a quick test to verify this will preserve the data.
create table #data(
ssl int
)
insert into #data values(1)
insert into #data values(2)
insert into #data values(3)
insert into #data values(4)
select * from #data
alter table #data
alter column ssl varchar(9)
select * from #data
And it never hurts to have backups before doing things like this. Even a quick insert into another table works if it's not a huge amount of data.
Problem
All, I have a populated table with the column 'SSN' as data type INT. Is it is possible to convert the column 'SSN', and the data within the column, to VARCHAR(#)'s. ``` ALTER TABLE Table1 MODIFY SSN varchar(9); ``` Will that work? Thank you! Any help is appreciated!