question

Reshmi avatar image
Reshmi asked

How to Convert IMAGE data to a plain text in SQL SERVER 2000?

I am working on a SQL Server 2000 migration and I need to convert Image data to plain text. Can any one help me out if any function exits for the same.

sqlsql-server-2000
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image
Matt Whitfield answered

What data is in the IMAGE column, exactly? Is it binary data that you need to represent in order to be able to insert it?

If so, you want to use CONVERT with a style code:

convert(nvarchar(max),[image_column_name],1)
3 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Image data is stored in Binary format. But on execution of above convert function, I am getting an error as below: Server: Msg 529, Level 16, State 2, Line 1 Explicit conversion from data type image to nvarchar is not allowed.
0 Likes 0 ·
Sorry - I completely missed the fact it was 2000, not 2005/8...
0 Likes 0 ·
Hi Matt, Any Idea on how I can proceede. Need a reverse functin also. That is to convert varchar data to Image too. Please help me out if you have any idea. thanks in advance,
0 Likes 0 ·
ThomasRushton avatar image
ThomasRushton answered

Converting from image data type in SQL 2000 can be done via binary / varbinary data types.

The following is a bit messy, but it works. Or at least seems to work in my limited testing...

create table testimg (id integer, imgdata image)
insert into testimg values (1, cast ('Test row 1' as image))
insert into testimg values (2, cast ('A longer line of test data' as image))
select id, imgdata, cast(cast(imgdata as binary) as varchar(1000)) FROM testimg

This'll return a varchar(1000) field containing the text version of what's stored in the field named imgdata.

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

farzad_1354 avatar image
farzad_1354 answered
hi all ## ##Solution one : cast(cast(imgdata as binary) as varchar(1000)) ## ##Solution two : convert (convert (varchar(max) , convert (varbinary (max) , ole)) I did that , both of solution have same result ## ##But my problems now is : 1- all wrapped text in ole will be remove I need them back 2- rich text coming in original ole such as {rft1\fbidis\ansi\ansicpg1256\ ..... I want plain text coming in results please help me to solve ASAP. THANKS GUYS
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Heh... I wondered if it was going to be something like this. No one in their right mind would store "just" text in an image column. The first step would be for you to Google for an RTF to text converter. In the future, please try to post all of the information about what you're trying to do. Leaving out the fact that the data stored in the image column was an RTF image was kind of important to trying to solve this problem.
0 Likes 0 ·
hongdida avatar image
hongdida answered
have a try with following code { QByteArray data; data = ((ui->enterTextEdit->toPlainText()).remove(0,1) ).toUtf8(); QString strOK; strOK = QString::fromUtf8(QByteArray::fromHex(data)); ui->resultTextBrowser->setText(strOK); } source from: [ http://www.qtcentre.org/threads/convert-image-data-type-to-plain-text/][1][image-conversion][2] [1]: http://www.qtcentre.org/threads/40609-How-to-convert-image-data-type-to-plain-text-and-back [2]: http://www.rasteredge.com/how-to/vb-net-imaging/image-converting/
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.