Possible to change varbinary values in table to varchar?

Posted on 2009-12-22
Last Modified: 2012-05-08
Is it possible to change varbinary values in table to varchar? I have set the column as the wrong datatype.  I would rather not lose the data by converting it.
Question by:mattkovo
    LVL 32

    Accepted Solution

    Using SSIS, Design the table and change the datatype.  I had no issues doing this, and the data returned perfectly.
    LVL 75

    Assisted Solution

    by:Aneesh Retnakaran
    yup possible, it involves these steps

    alter table tableName add tmpColumn varchar(100) ---you may have to change the tablename and the fieldlength

    update TableName
    set tmpColumn = CONVERT(varchar(100), varbinaryColumn )

    exec sp_rename  'TableName.varbinaryColumn', 'varbinaryColumn_tmp' ,'COLUMN'
    exec sp_rename  'TableName.tmpColumn', 'varbinaryColumn' ,'COLUMN'

    --now chall the columns and run the following
    --alter table tableName  drop column varbinaryColumn

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
    In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now