您的位置:首页技术文章
文章详情页

SQL Server: convert varbinary to varchar

【字号: 日期:2023-10-31 09:51:00浏览:67作者:猪猪

Use CAST; or; CONVERT

select convert (varbinary (20) , 'select') it gives = 0x73656c656374then you can convert that to a varcharselect convert (varchar (20), 0x73656c656374 ) it gives 'select'

Use master.dbo.fn_varbintohexsubstring(1,@binvalue,1,0)

master.dbo.fn_varbintohexsubstring(1,@binvalue,1,0)

declare @binvalue varbinary(256),@vcharvalue nvarchar(256)set @binvalue = 0xF5FF3FED3B055DF7EC27251FBC80EE48select @vcharvalue = 'aa' + master.dbo.fn_varbintohexsubstring(1,@binvalue,1,0)

print @vcharvalue

it gives = 0xF5FF3FED3B055DF7EC27251FBC80EE48

Use master.dbo.fn_varbintohexstr(@binvalue)

declare @binvalue varbinary(256),@vcharvalue nvarchar(256)set @binvalue = 0xF5FF3FED3B055DF7EC27251FBC80EE48select @vcharvalue = 'aa' + master.dbo.fn_varbintohexstr(@binvalue)

print @vcharvalue

it gives = 0xF5FF3FED3B055DF7EC27251FBC80EE48

http://www.cnblogs.com/skyfei/archive/2006/09/13/502861.html

标签: Sql Server 数据库