three ways - one would be to look into Peso's suggestion: XQuery. Another would be to loop through your values to get them one at a time as above. Another could be to use a function as I mentioned earlier. It would be the reverse of the built-in one sys.fn_varbintohexstr. Here is one I wrote some time ago if you can't find anything better:if object_id('dbo.fn_hexStrToVarbin') > 0 drop function dbo.fn_hexStrToVarbingocreate function dbo.fn_hexStrToVarbin (@s varchar(8000))returns varbinary(4000)/*this function takes a hexidecimal string, converts, and returns it as a varbinary(4000)sample call:select dbo.fn_hexStrToVarbin(sHex)from ( select '0x000000002FDAF785' sHex union all select '0x0A' union all select '0x060A' union all select '' union all select '0x06' union all select replicate('FF', 3999) + 'AA' ) a--works for nvarchar(4000) tooselect dbo.fn_hexStrToVarbin(N'' + replicate('FF', 1999) + 'AA')*/asbegin declare @out varbinary(4000) ,@n int ,@l int set @s = replace(@s, '0x','') select @l = len(@s) ,@n = 1 while @n <= @l-1 begin select @out = coalesce(@out + b, b) from ( select b = convert(binary(1), (convert(varbinary, charindex(substring(@s, @n, 1), '0123456789ABCDEF')-1) * 16) + isNull(nullif(charindex(substring(@s, @n+1, 1), '0123456789ABCDEF')-1,-1),0)) ) d set @n = @n+2 end return @outendgoIt assumes the input comes in Pairs of hex digits (one byte each). So it looks like your sample value is missing a leading "0":'0A5000000020'. So if your data has odd numbers of digits you may have an issue.Then you can use it with something like this:select convert(bigint, dbo.fn_hexStrToVarbin(a.Client_id)) from [application] as a where a.application_id = @application_id
Be One with the OptimizerTG