Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 convert data in image column

Author  Topic 

barnabeck
Posting Yak Master

236 Posts

Posted - 2014-12-10 : 16:58:35
I have a string stored in a column of type image that I need to do string operations with in order to decode the containing infomation.

data [image] = 0x07FD0707FD0102F001000054004C005300410000000054004C00530041000000FF...

I can't cast or convert to nvarchar(max), varchar(max) as I always get an error. Explicit conversion from data type image to varchar(max) is not allowed.

I tried CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), DATA))
which doesn't throw an error but seems to interprete the hexadecimal code to ascii characters and therefore is useless (ýýð...)

Any sugestion?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-12-10 : 17:16:59
It's my understanding that you would need to do this in the application and not in T-SQL, so you'd have to pull back the image to the app, do your manipulation there and then send the image back to SQL.


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

barnabeck
Posting Yak Master

236 Posts

Posted - 2014-12-10 : 17:33:40
I can't do anything about the format. The content of that string is one condensed log entry line that our ERP is storing in that table. I need to query that data and therefore have to do it in T-SQL.

I did now CAST(CONVERT(VARBINARY(MAX), DATA) as nvarchar(max)) and it turns chinese.... :(
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-12-10 : 17:42:55
I don't think it's possible. Write a simple .net app or similar to do this work. Maybe you can get away with doing it in a CLR function, but I'm not sure.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -