String into 16 binary function

Source: Internet
Author: User

/****************************

The string is converted into 16 binary

No cannot.

qq:75492895

Email: [Email protected]

****************************/

--Create FUNCTION (Suiyunonghen (not cannot))

Create Function Varchartohex (@Str Varchar (400))

Returns varchar (800)

As

Begin

DECLARE @i int, @Asi int, @ModS int, @res varchar, @Len int, @Cres varchar (4), @tempstr varbinary (400)

Select @i = 1, @res = ", @len =datalength (@str), @tempStr = Convert (varbinary, @str)

While @i<[email protected]

Begin

Select @Asi = substring (@tempstr, +), @Cres = "

While @Asi <> 0

Begin

Select @Mods = @Asi% 16,

@Cres =case When (@Mods > 9) then Char (Ascii (' A ') [email protected]) [email protected] else Cast (@Mods as varchar (4)) + @c Res end,

@Asi = @Asi/16

End

Select @res = @res + @Cres, @tempStr = substring (@tempStr, 2, @len-1), @i = @i+1

End

Return @res

End

Go

--Test example

SELECT dbo. Varchartohex (' leaves ')

--Running results

/*

D2b6d7d3

*/

String into 16 binary function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.