Cast varbinary to Unicode  
Author Message
CRyder





PostPosted: Mon Sep 17 02:50:01 PDT 2007 Top

SQL Server Developer >> Cast varbinary to Unicode

Hi,
I'm working with SQL 2000, I have a table called Items with an Image field
called Content, this field contains an XML Serialization, I'm using the
following command to extract the XML from the table:

SELECT CAST(CAST(Content AS varbinary(8000)) AS varchar(8000)) AS Content
FROM Items

This command works fine when the XML contains English characters. When the
XML contains foreign characters like Russian or Chinese I'm not getting the
correct characters, how can I change the command for getting the correct
foreign characters?

Thanks
Meir

SQL Server181  
 
 
ML





PostPosted: Mon Sep 17 02:50:01 PDT 2007 Top

SQL Server Developer >> Cast varbinary to Unicode Try casting to a unicode data type (i.e. NVARCHAR or NTEXT).


ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
 
 
Meir





PostPosted: Mon Sep 17 03:23:47 PDT 2007 Top

SQL Server Developer >> Cast varbinary to Unicode I've tried that, I'm getting garbage instead of Russian characters.


> Try casting to a unicode data type (i.e. NVARCHAR or NTEXT).
>
>
> ML
>
> ---
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/


 
 
ML





PostPosted: Mon Sep 17 03:36:04 PDT 2007 Top

SQL Server Developer >> Cast varbinary to Unicode What is the encoding used in the XML?


ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
 
 
Meir





PostPosted: Mon Sep 17 06:09:22 PDT 2007 Top

SQL Server Developer >> Cast varbinary to Unicode I send you an example, I insert some russian characters to an image field in
a table, but I can't display them back, I'm not sure this mail will display
russian characters, if it doesn't please insert them for testing

CREATE TABLE [dbo].[Items] (
[ID] [int] NOT NULL ,
[Content] [image] NULL ,
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

insert Items(Id,Content)
values(1,cast('?????? ???????\r\n ???????????? ?????? ??????????? ????' as
image))

select cast(cast(Content as varbinary(4000))as nvarchar(4000)) from items




> What is the encoding used in the XML?
>
>
> ML
>
> ---
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/


 
 
ML





PostPosted: Mon Sep 17 06:34:05 PDT 2007 Top

SQL Server Developer >> Cast varbinary to Unicode Yeah, well, you're sample may not have come through the way you might have
expected.

Post a sample binary representation instead (e.g. all the characters in the
alphabet).


ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/