???
------解决方案--------------------
declare @b varbinary(20)
set @b=0XA
select cast(@b as int)
--result
-----------
10
(1 row(s) affected)
------解决方案--------------------
binary 为二进制类型
二进制常量以 0x(一个零和小写字母x)开始,后面跟着位模式的十六进制表示。例如,0x2A 表示十六进制的值 2A
------解决方案--------------------
--引用
CREATE FUNCTION dbo.f_hex_dec(@s varchar(16))
RETURNS bigint
AS
BEGIN
DECLARE @i int,@result bigint
SELECT @i=0,@result=0,@s=RTRIM(LTRIM(UPPER(REVERSE(@s))))
WHILE @i <LEN(@s)
BEGIN
IF SUBSTRING(@s,@i+1,1) not between '0 ' and '9 ' and SUBSTRING(@s,@i+1,1) not between 'A ' and 'F '
BEGIN
SELECT @result=0
break
END
SELECT @[email protected]+(CHARINDEX(SUBSTRING(@s,@i+1,1), '0123456789ABCDEF ')-1)*POWER(16,@i),@[email protected]+1
END
RETURN @result
END
GO
--
select dbo.f_hex_dec( 'A ')
--res
10