これが実際には 16 進数の文字列表現であると仮定するとnum
、いくつかのユーザー定義関数を使用して整数に変換できると思います。
-- Based on Feodor's solution on
-- http://blog.sqlauthority.com/2010/02/01/sql-server-question-how-to-convert-hex-to-decimal/
CREATE FUNCTION fn_HexToInt(@str varchar(16))
RETURNS BIGINT AS BEGIN
SELECT @str=upper(@str)
DECLARE @i int, @len int, @char char(1), @output bigint
SELECT @len=len(@str),@i=@len, @output=case WHEN @len>0 THEN 0 END
WHILE (@i>0)
BEGIN
SELECT @char=substring(@str,@i,1)
, @output=@output
+(ASCII(@char)
-(case when @char between 'A' and 'F' then 55
else case when @char between '0' and '9' then 48 end
end))
*power(16.,@len-@i)
, @i=@i-1
END
RETURN @output
END
-- Example conversion back to hex string - not very tested
CREATE FUNCTION fn_IntToHex(@num int)
RETURNS VARCHAR(16) AS BEGIN
DECLARE @output varchar(16), @rem int
SELECT @output = '', @rem=0
WHILE (@num > 0)
BEGIN
SELECT @rem = @num % 16
SELECT @num = @num / 16
SELECT @output = char(@rem + case when @rem between 0 and 9 then 48 else 55 end) + @output
END
RETURN @output
END
select dbo.fn_HexToInt ('7FFF') -- = 32767
select dbo.fn_IntToHex(32767) -- = 7FFF
だからあなたは試すことができます
UPDATE myTable
SET num = dbo.fn_IntToHex(dbo.fn_HexToInt(num) + 4000)