سؤال

I am trying to query a table that contains some XML values in varbinary format and having difficulty getting meaningful output.

I have looked at several Google results and Stack Overflow answers such as this one, but the answers suggested do not seem to work for me.

My latest version of the query is as follows:

select top 100 EntryDataAndTime, EntryType, RequestID, Sequence, ServerName,
       cast(XML as varchar(max)) as xml_string
  from RequestResponseLog

This returns the final column in a format like: ‹½U_oÓ0//¼ ¾ê+Zœ...

I have also tried:

select top 100 EntryDataAndTime, EntryType, RequestID, Sequence, ServerName,
       Convert(varchar(8000), XML, 2) as xml_string
  from RequestResponseLog

which seems to return the final column in hex format e.g. 1F8B0800000000000400BD555F6FD330102F2FBC...

Most of the Google results and the Stack Overflow question I referred to above include a step where you do something like...

declare @b varbinary(max)
set @b = 0x5468697320697320612074657374

before you use the cast function. I am not entirely clear what the 0x54.. value is, but this seems to assume that you only want to convert a single value rather than multiple rows as I am, unless I have misunderstood?

Any help to get the conversion to readable strings working within the query would be greatly appreciated.

هل كانت مفيدة؟

المحلول

It turns out after investigating further than some compression had been done at the application level in C# before writing this data to the database as BLOBs. Because of this there are no standard SQL server functions to translate the data into human readable form, I would need to reverse the process that compressed the data in an application.

I have left this question here rather than deleting in-case anyone else has a similar issue in the future.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top