I am trying to take a hex value like 0x3A, 0x2f and convert it to it's ascii equivlent. I have code below that works but it needs to run inside of a function and since only other functions and extended stored procedures can be executed from within a function it is failing.
The function takes a string (comes from IIS log file) that is a long URL similiar to the following: so ascii characters like ":" and "/" have been converted to their hex counterparts %3A or 0x3A in tsql, %2F or 0x2F and I need to convert them back.
declare @v varchar(20), @sql nvarchar(MAX), @ch varchar(20)
select @v = '3A'
select @sql = 'SELECT @ch = convert(varchar, 0x' + @v + ')'
print @sql
EXEC sp_executesql @sql, N'@ch varchar(30) OUTPUT', @ch OUTPUT
SELECT @ch,upper(substring(master.sys.fn_varbintohexstr(convert(varbinary, @ch)),3, 2*len(@ch)))
Anyone have another way of doing this that doesn't require dynamic sql? I'd rather not write this as an extended stored procedure.
If SSIS has the ability to do this via a transform task that will work too.
Thanks
The function takes a string (comes from IIS log file) that is a long URL similiar to the following: so ascii characters like ":" and "/" have been converted to their hex counterparts %3A or 0x3A in tsql, %2F or 0x2F and I need to convert them back.
declare @v varchar(20), @sql nvarchar(MAX), @ch varchar(20)
select @v = '3A'
select @sql = 'SELECT @ch = convert(varchar, 0x' + @v + ')'
print @sql
EXEC sp_executesql @sql, N'@ch varchar(30) OUTPUT', @ch OUTPUT
SELECT @ch,upper(substring(master.sys.fn_varbintohexstr(convert(varbinary, @ch)),3, 2*len(@ch)))
Anyone have another way of doing this that doesn't require dynamic sql? I'd rather not write this as an extended stored procedure.
If SSIS has the ability to do this via a transform task that will work too.
Thanks