Converting "image" to "nvarchar"?

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?

Thanks.
takoraptorAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
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
1
 
Anthony PerkinsCommented:
>>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.
0
 
takoraptorAuthor Commented:
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!
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.