Converting "image" to "nvarchar"?

Posted on 2006-05-05
Medium Priority
1 Endorsement
Last Modified: 2008-03-17
Hi All,

I am trying to run a SELECT statement against a database table to be able to view (in human readable form) the contents of a field that is of type "image". Ideally I would like it in ntext or nvarchar, so that I can read it. Unfortunately, I have not been able to find a way of doing this. Would you have suggestions please?

Question by:takoraptor
LVL 75

Accepted Solution

Aneesh Retnakaran earned 200 total points
ID: 16619720
You can use the CAST to convert the image column to varbinary, binary or timestamp. from those you can convert to nvarchar. You can read only the binaryvalues stored in the image column
SELECT CAST(CAST (urImageColumn AS varbinary) AS varchar(30)) FROM urTble
LVL 75

Expert Comment

by:Anthony Perkins
ID: 16619893
>>I am trying to run a SELECT statement against a database table to be able to view (in human readable form)<<
Cannot be done with T-SQL alone.

Author Comment

ID: 16631921
Thanks! I had more than 30 chars in the field but that issue was trivially solved by doing a varbinary(8000) on the query you gave me... I guess that since varbinary does not accept more than 8000 chars, I cannot use this technique to see fields which have a bigger payload, but that is fine.

Thanks to aneeshattingal and acperkins for their responses!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question