Convert VarBinary to VarChar in SQL
Binary format is very difficult to read. Suppose you get task to replace the some text of for field whose datatype is image or varbinary. We can achieve the task in different different way.
Below script help to convert the varbinary format to readable format i.e. varchar.
convert(varchar(8000), convert(varbinary(8000),<ColumnName>))
SQL Scripts to update text for field varbinary
UPDATE <Table_Name>
SET <Column_Name> =convert(varbinary(Max),REPLACE(convert(varchar(8000), convert(varbinary(8000),<Column_Name>)), 'OLD VALUE', 'NEW VALUE') )
WHERE convert(varchar(8000), convert(varbinary ,8000),Column_Name)) like '%OLD VALUE%'
- Table Name: Actual Table Name
- Column Name: Column Name whose data type is varbinary and you want to change the text.
- OLD Value: Old Value to be changed
- New Value: Updated Value
Even you can perform simple select statement to read the text
select convert(varchar(8000), convert(varbinary(8000),<ColumnName>)) from Table_Name
- Submitted By Vibhuti Singh
- Category ms-sql
- Created On 22-Aug-2024