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?
A binary string is a sequence of octets or bytes. BYTEA and RAW are synonyms for VARBINARY.
varbinary [ ( n | max) ] Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length.
SqlException: 'Implicit conversion from data type varchar to varbinary(max) is not allowed.
Try:
DECLARE @varbinaryField varbinary(max); SET @varbinaryField = 0x21232F297A57A5A743894A0E4A801FC3; SELECT CONVERT(varchar(max),@varbinaryField,2), @varbinaryField
UPDATED: For SQL Server 2008
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With