We help IT Professionals succeed at work.

CONVERT(varchar, <image  datatype>)   ???

Tom Knowlton
Tom Knowlton asked
on
599 Views
Last Modified: 2008-03-17
select convert(nvarchar,test) from delete_tom_test


does not work



field   test  is   of   type    image
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Tom KnowltonWeb developer

Author

Commented:
That tells me what I cannot do.


How can I view what is stored in an image    datatype    as   text ????
Tom KnowltonWeb developer

Author

Commented:
I tried NESTING the casts like this:



select cast(cast(test as varbinary) as varchar(8000)) from delete_tom_test



YIELDS:


AAAAAAAAAAAAAAA=



Which is not correct
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>How can I view what is stored in an image    datatype    as   text ????<<
Simply put:  You can't.
CERTIFIED EXPERT
Top Expert 2006

Commented:
You can't. SQL server just doesn't know how to convert from image to varchar.
Tom KnowltonWeb developer

Author

Commented:
Might .NET know how to do it.....like a C#  application?
CERTIFIED EXPERT
Top Expert 2006

Commented:
No. Only the person who insterted would know what is in that column :) It is a binary data. It could be anything. So read it and you would get byte array. Then use GetChars to convert to string.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemTextASCIIEncodingClassGetCharsTopic.asp
CERTIFIED EXPERT
Top Expert 2006

Commented:
Obviouly that would work only if the data in the column is valid text data to begin with. What I mean by that, if someone inserted jpeg data in that columns, no code can convert it to text.
Tom KnowltonWeb developer

Author

Commented:
So there is no way to view an   image   datatype   as    text           no matter how many hoops I jumpt through?


Or are you saying...specifically.....varchar won't work   but other conversions will work  ?????
CERTIFIED EXPERT
Top Expert 2006

Commented:
>>no matter how many hoops I jumpt through?

No :)

Not in T-SQL.
Tom KnowltonWeb developer

Author

Commented:
Oh.....all right then.

Boy will my friend be MAD.    LOL.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.