varbinary to varchar

varbinary to varchar

am 07.12.2007 02:15:56 von Analizer1

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

Re: varbinary to varchar

am 07.12.2007 05:31:54 von Plamen Ratchev

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

Re: varbinary to varchar

am 07.12.2007 19:30:54 von Analizer1

that worked Fantastic....
thank you very much

"Plamen Ratchev" wrote in message
news:tJudnR8PRv38UcXanZ2dnUVZ_tWtnZ2d@speakeasy.net...
> 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