/****************************
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