SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Issue converting image data type to string


Issue converting image data type to string

Author
Message
thinkink07
thinkink07
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 15
I've done some research on this and have yet to fully understand why it's happening and how I can fix it (which brought me here). I have a table that stores plain text data as an image data type. I've attempted converting it to a varbinary, then to a (n)varchar but the data returned is a symbol and not the expected value. There is a similar column in another table that handles thisconversion cleanly.

select NodeID as ID, DateTime, Calls, Meters as ImgData, convert(varbinary(8000), Meters ) as ImgToVarbinary, convert(nvarchar(max), convert(varbinary(8000), Meters )) as ImgToVarbinaryToNvar

from Node_Real_Time where NodeID = 68211




Results
ID DateTime Calls ImgData ImgToVarbinary ImgToVarbinaryToNvar
68211 2017-12-21 21:12:12.000 1076 0x340400003404... 0x340400003404... д

Any thoughts? Thanks in advance...
Thom A
Thom A
SSC-Forever
SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)

Group: General Forum Members
Points: 46230 Visits: 15719
Try converting back to varchar, rather than nvarchar? If your initial string was a varchar, you need to convert back to that. For example:
SELECT CONVERT(nvarchar(100),CONVERT(varbinary,CONVERT(image,'sdfashgu3o4ggjkxchbvkjasgvftkj'))); --varchar to nvarchar
SELECT CONVERT(varchar(100),CONVERT(varbinary,CONVERT(image,'sdfashgu3o4ggjkxchbvkjasgvftkj'))); --varchar to varchar

Also, at least on SQL Server 2012 SP4, you can't CONVERT an nvarchar to image, thus this seems to imply more so that your original data type was varchar.


Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does :-P

Please always remember to encapsulate your code in IFCode Markup. For example [code=sql] [/code].
Click here to read Jeffs Guide on how to post SQL questions, and get swift and helpful answers from the community
thinkink07
thinkink07
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 15
Yeah I tried converting to varchar instead with similar results. I know what the data consists of but starting to wonder if it's not stored as plain text.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search