Hex to Ascii Help

Hi.  I am trying to convert the contents of a field to ASCII.

The Field is of Image type and when viewed through the Gui is says Binary Data but when retreived via a select statement this is what is returned, HEX .

0x0015C5EF900800144F6AA35A080045000089AE464000400669710A000D050A0001B3A16761AF31A889D7FFB57FD25018C1E88AA300000105010100640401000000000000006100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005783000000000000E577

If I put this in a Hex to ASCII converter I get.

?????????Oj?Z??E????F@?@?iq?????????ga?1???????P????????????d?????????a???????????????????????????????????????????????????????????????????????W????????w

This the correct data (I cannot post an example with readable information)

How do I use a CLR or the like to convert this date in a SQL select statement?

Thanks

Matthew
Matthew_LoweAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Matthew_LoweAuthor Commented:
I have been looking at this and it kind of works but it only seems to convert the first 30 chars (I have increased all defs to MAX)

This would be great if it could convert the whole string (see above) .

I just cannot seem to work out how to do that. Any ideas?

Matthew
quincydudeCommented:
you see that bit in the code with
N'@ch varchar(30) OUTPUT    ?

could this be the cause?
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Matthew_LoweAuthor Commented:
The code I am running is below. I had already changed it but there still seems to be a limit.

Thanks

Matthew  

declare @v varchar(8000), @sql nvarchar(4000), @ch varchar(8000)
select @v = '0x0015C5EF900800144F6AA35A080045000109AE3E4000400668F90A000D050A0001B3A17761AFF08CE0C0FF862F615018C1E8DE060000010501010064020100000000000000E1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011D82FBEFAA0000000000005783000000000000000F000000000000000000000000000000560000715753505F506F7274616C5F4F5554004A4D53436F7272656C6174696F6E49443D2749443A37353339613A31316438326662656661653A376239633A37663030303030313A31316438643862613333323A32383666653631316438643635353835656536302700'
select @sql = 'SELECT @ch = convert(varchar, ' +@v + ')'
EXEC sp_executesql @sql, N'@ch varchar(8000) OUTPUT', @ch OUTPUT
SELECT @ch,
upper(substring(master.sys.fn_varbintohexstr(convert(varbinary, @ch)),
3, 2*len(@ch))
Matthew_LoweAuthor Commented:
I have solved the reading all the values (see below). Now its sees to not like some special chars and stops. If I put a string in that only contains valid ASCII Chars its OK.

Is there a way to error check etc on this?

Mattew

declare @v varchar(8000), @sql nvarchar(4000), @ch varchar(8000)
select @v = '0x000D050A0001B3A17761AFF08CE0C0FF862F615018C1E8DE060000010501010064020100000000000000E1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011D82FBEFAA0000000000005783000000000000000F000000000000000000000000000000560000715753505F506F7274616C5F4F5554004A4D53436F7272656C6174696F6E49443D2749443A37353339613A31316438326662656661653A376239633A37663030303030313A31316438643862613333323A32383666653631316438643635353835656536302700'
select @sql = 'SELECT @ch = convert(varchar(MAX), ' +@v + ')'
EXEC sp_executesql @sql, N'@ch varchar(8000) OUTPUT', @ch OUTPUT
SELECT @ch,
upper(substring(master.sys.fn_varbintohexstr(convert(varbinary(MAX), @ch)),
3, 2*len(@ch)))
Matthew_LoweAuthor Commented:
00 is the issue. If I take out all the 00 from the HEX its OK.

I now need to find a way to Test for 00 and remove or replace with another char.

Thanks

Matthew
Matthew_LoweAuthor Commented:
Doing a Regex replace for 00 with 3f (?) works well.

Thanks for the help.

Matthew

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Matthew_LoweAuthor Commented:
All fixed now
Matthew_LoweAuthor Commented:
All fixed now
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.