dbTalk Databases Forums  

varbinary to varchar

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss varbinary to varchar in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Analizer1
 
Posts: n/a

Default varbinary to varchar - 12-06-2007 , 07:15 PM






can you conver a Varbinary to varchar

declare @sid varbinary(85)
select @sid = suser_sid("mydomain\mynam")

// how to convert the sid to a string or do i need to
//convert it in code to byte array and back to hex string

thanks



Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: varbinary to varchar - 12-06-2007 , 10:31 PM






Hi,

One way to convert the varbinary to a hex string is to use the built-in
undocumented function fn_varbintohexstr, like this:

SELECT master.dbo.fn_varbintohexstr(@sid)

But please have in mind it is undocumented and unsupported (I see it is
still there even in SQL Server 2008 under the sys schema, but not guaranteed
to exist in the future).

An alternative and more reliable way would be to write your own TSQL or CLR
(if on SQL Server 2005) function, here is one example in TSQL:
http://support.microsoft.com/?id=104829

Another solution is to do this in client code.

HTH,

Plamen Ratchev
http://www.SQLStudio.com


Reply With Quote
  #3  
Old   
Analizer1
 
Posts: n/a

Default Re: varbinary to varchar - 12-07-2007 , 12:30 PM



that worked Fantastic....
thank you very much

"Plamen Ratchev" <Plamen (AT) SQLStudio (DOT) com> wrote

Quote:
Hi,

One way to convert the varbinary to a hex string is to use the built-in
undocumented function fn_varbintohexstr, like this:

SELECT master.dbo.fn_varbintohexstr(@sid)

But please have in mind it is undocumented and unsupported (I see it is
still there even in SQL Server 2008 under the sys schema, but not
guaranteed to exist in the future).

An alternative and more reliable way would be to write your own TSQL or
CLR (if on SQL Server 2005) function, here is one example in TSQL:
http://support.microsoft.com/?id=104829

Another solution is to do this in client code.

HTH,

Plamen Ratchev
http://www.SQLStudio.com



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.