Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Image Type Data to XML/Plain Text in SQL Server

I'm working on SSRS Report.

I have the content with Data type Image. I want to convert it into plain-text or XML. Is it possible?

I am not providing the sample data as there is huge data. (Whole report content saving to image so we can understand)

Suggest me the best solution.

like image 591
pedram Avatar asked Oct 19 '22 18:10

pedram


2 Answers

Tried below and working fine but appending extra string like this  to output.

Used RIGHT() to chop off first 3 characters - working fine

SELECT 
RIGHT(CONVERT(VARCHAR(MAX),CONVERT(VARCHAR(MAX),CONVERT(VARBINARY(MAX) ,ImageDataField))),
LEN(CONVERT(VARCHAR(MAX),CONVERT(VARCHAR(MAX),CONVERT(VARBINARY(MAX) ,ImageDataField))))-3)
like image 81
pedram Avatar answered Oct 21 '22 10:10

pedram


This works from SQL Server Management Studio, when the current database is the ReportServer database.

-- given a NonRemitted_detail.rdl file that was deployed to a report server on path /Jacket Generator 
-- the contents can be found as XML with this:
SELECT CONVERT(XML, CONVERT(VARBINARY(MAX), Content)) AS rdl_file_content
    FROM ReportServer.dbo.[Catalog]
    WHERE [Path] = N'/Jacket Generator/NonRemitted_detail'

Nearly identical. Whitespace between XML elements has been stripped. The opening XML declaration is missing.

like image 25
dfrevert Avatar answered Oct 21 '22 08:10

dfrevert