tsql - Stopping T-SQL converting Hex to ASCII -
i'm trying trimmed hex value int. converting int hex no troubles using;
convert(varbinary(1),43) --this creating 0x2b result
i want show value 2b when sort of conversion varchar(), cast or right() hex converted ascii character , can't it.
does know way of preserving hex value while removing leading 0x?
if value in range 0 255 can use brute force:
-- 1 value. declare @vb varbinary(1) = 43; select @vb [varbinary], substring( '0123456789abcdef', ascii( @vb ) / 16 + 1, 1 ) + substring( '0123456789abcdef', ascii( @vb ) & 15 + 1, 1 ) [hex]; -- test range 0 255. numbers ( select 0 number union select number + 1 numbers number < 255 ), numberswithvarbinary ( select number, cast( number varbinary(1) ) vb numbers ) select vb [varbinary], substring( '0123456789abcdef', ascii( vb ) / 16 + 1, 1 ) + substring( '0123456789abcdef', ascii( vb ) & 15 + 1, 1 ) [hex] numberswithvarbinary option ( maxrecursion 0 );
extending range left exercise reader.
Comments
Post a Comment