April 4, 2010 at 11:31 pm
I want to Convert image field in my table to varchar but when I use:
select convert(varchar(max),convert(varbinary(max),ImgField)), Id from Table1
it returns ÿØÿà
I am hanging on this for last 4 days but nt finding anything about this...
April 5, 2010 at 6:27 am
if you are sure the image field contains text that was converted to varbinary, then you need to convert to nvarchar isntead of varchar i think.
here's a proof of concept: the first part works perfectly, where the second, using varchar instead of nvarchar, does not convert correctly:
DECLARE @var VARBINARY(128),
@res NVARCHAR(64)
SET @var = CAST(N'Hello World' AS VARBINARY(128))
PRINT @var
--results: 0x480065006C006C006F00200057006F0072006C006400
SET @res = CAST(@var AS NVARCHAR(64))
PRINT @res
--results: Hello World
--The same but using CONVERT:
--####################
--fails because it's not nvarchar!
--####################
DECLARE @var VARBINARY(128),
@res VARCHAR(64)
SET @var = CAST('Hello World' AS VARBINARY(128))
PRINT @var
--results: 0x48656C6C6F20576F726C64
SET @res = CAST(@var AS NVARCHAR(64))
PRINT @res
--results: ?????d
Lowell
April 5, 2010 at 7:05 am
No actually its an image data in it.
The purpose for convertion is To generate InsertScripts for the table. For this I want string representaion of the Image Data. When I use
select convert(varchar(max),convert(varbinary(max),imagefield)) from table1
it returns ÿØÿà
April 6, 2010 at 3:19 am
Please reply. its very important. I am running out of time
April 6, 2010 at 5:59 am
i've never scripted images out, mostly because they can't be represented in a string;
this link might help you, but everything i've ever seen shows that you have to treat images differently...
Lowell
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply