strike_noir strike_noir - 6 months ago 14
SQL Question

SQL Server converting varbinary to string

I want to do conversion in T-SQL from a

varbinary
type to string type

Here is an example :

First I got this
varbinary


0x21232F297A57A5A743894A0E4A801FC3


And then I want to convert it to

21232f297a57a5a743894a0e4a801fc3


How to do this?

Answer

Try:

DECLARE @varbinaryField varbinary(max);
SET @varbinaryField = 0x21232F297A57A5A743894A0E4A801FC3;

SELECT CONVERT(varchar(max),@varbinaryField,2), 
@varbinaryField

UPDATED: For SQL Server 2008