Copy data from one column to another with different formats

I have a table where I want to move data that is in a INT column to an Alphanumeric column in the same table. I tried doing an insert into that column with this command below but it didn't work out as I expected and that might be because of the different formats.

UPDATE <table>
SET <column from copy>=<column to copy>
WHERE <column from copy> IS NOT NULL

There are 5773 rows in this table so I can't do them one by one. I think I need to use a CAST statement but don't know how iterate between each record.
TimSr. System AdminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Faiga DiegelSr Database EngineerCommented:
UPDATE <table>
SET CAST(<column from copy> AS VARCHAR(20) = <column to copy>
WHERE <column from copy> IS NOT NULL
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
UPDATE <table>
SET <column to copy> = CAST(<column from copy> AS VARCHAR(20))
WHERE <column from copy> IS NOT NULL
0
Simone BSenior E-Commerce AnalystCommented:
It may not be the data type, as a string field should accept an integer. In an update statement the column name immediately after SET is the one that gets the new value. I.e. the column that you are copying to. However, if you're copying the INT column to the CHAR column:

UPDATE <table>
SET CHARColumn = CAST(INTColumn as XXX)
WHERE INTColumn IS NOT NULL

In the CAST, XXX is the data type of the string column.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>but don't know how iterate between each record.
This shouldn't be necessary as long as there's no logic that dicates a different expression for some rows versus others.
0
TimSr. System AdminAuthor Commented:
Thanks for all your help. This worked perfectly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.