SQL SERVER 十六进制转十进制

Create PROCEDURE sp_hexadecimal
    @binvalue varbinary(255),
    @hexvalue varchar(255) OUTPUT
AS
        DECLARE @charvalue varchar(255)
        DECLARE @i int
        DECLARE @length int
        DECLARE @hexstring char(16)

        SELECT @charvalue = ''
        SELECT @i = 1
        SELECT @length = DATALENGTH(@binvalue)
        SELECT @hexstring = '0123456789abcdef'

        WHILE (@i <= @length)
        BEGIN
                DECLARE @tempint int
                DECLARE @firstint int
                DECLARE @secondint int

                SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
                SELECT @firstint = FLOOR(@tempint/16)
                SELECT @secondint = @tempint - (@firstint*16)
                SELECT @charvalue = @charvalue +
                SUBSTRING(@hexstring, @firstint+1, 1) +
                SUBSTRING(@hexstring, @secondint+1, 1)
                SELECT @i = @i + 1
        END
        
        
        SELECT @hexvalue = upper(@charvalue)

    原文作者:进制转换
    原文地址: https://blog.csdn.net/smahorse/article/details/7836360
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞