Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

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

select convert(nvarchar,test) from delete_tom_test


does not work



field   test  is   of   type    image
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

That tells me what I cannot do.


How can I view what is stored in an image    datatype    as   text ????
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
>>How can I view what is stored in an image    datatype    as   text ????<<
Simply put:  You can't.
You can't. SQL server just doesn't know how to convert from image to varchar.
Might .NET know how to do it.....like a C#  application?
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
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.
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  ?????
>>no matter how many hoops I jumpt through?

No :)

Not in T-SQL.
Oh.....all right then.

Boy will my friend be MAD.    LOL.