Re: UNICODE data in a SQL statement encoded with ANSI character sequence....

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Bart Duncan [MSFT] (bartd_at_online.microsoft.com)
Date: 07/01/04


Date: Thu, 01 Jul 2004 23:17:52 GMT

The most compact way would be to simply send the actual Unicode
characters to SQL so that they didn't have to be encoded numerically. It
is possible to insert Unicode data as a raw binary value, but you have to
be careful to byte swap each character because SQL runs on x86, which is
a little endian processor architecture. For example, the Unicode
character U+3478 is actually represented in memory as 0x7834 (the order
of the two bytes is reversed). The two-character Unicode string U+3478
followed by U+2976 would be 0x78347629 (represented in hex). You could
insert this into an nvarchar column in SQL using: INSERT INTO tbl VALUES
(0x78347629).

HTH,
Bart
------------
Bart Duncan
Microsoft SQL Server Support

Please reply to the newsgroup only - thanks.
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
From: "Donovan J. Edye" <donovan@edye.wattle.id.au>
Subject: Re: UNICODE data in a SQL statement encoded with ANSI character
sequence....
References: <enRf39rWEHA.3716@TK2MSFTNGP11.phx.gbl>
<O4vjPHwWEHA.2616@cpmsftngxa10.phx.gbl>
User-Agent: XanaNews/1.16.3.1
Message-ID: <ueNcrwwWEHA.1888@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.sqlserver.programming
Date: Fri, 25 Jun 2004 16:28:48 -0700
NNTP-Posting-Host: 203-217-58-114.dyn.iinet.net.au 203.217.58.114
Lines: 1
Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP
11.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.programming:453422
X-Tomcat-NG: microsoft.public.sqlserver.programming

Bart Duncan [MSFT] wrote:

> SQL doesn't understand escape sequences like #3478. You could
> potentially use the NCHAR function like so:
>
> UPDATE tblMyTable SET MyUnicodeField = NCHAR (0x3478) + NCHAR
> (0x2976)
>
> HTH,
> Bart
Thanks for that, it looks like a plan. I was wondering however if it
was possible to do a single conversion rather than NCHAR() + NCHAR()
etc. but instead NTEXT(0x34780x2976) or similair. I need to send this
data over a comms link so am trying to make it as small as possible.

--D



Relevant Pages

  • Re: VB - Ascii to Unicode and then Unicode to UTF-8 conversion (Very desperate!!)
    ... Latin together) then you have to use a Unicode column type. ... AscW returns the real Unicode character ... for Chinese characters, ... then the next thing to worry about is your CSV file. ...
    (microsoft.public.vb.general.discussion)
  • SSIS not converting between non-unicode and unicode
    ... I don't know about you, but adding data conversion objects, and selecting each field... ... asking for a fix to automatically convert non-unicode to unicode in 2005!!! ... I am converting a simple (at least in the SQL Server 2000 DTS days) to this ... error message stays the same ...
    (microsoft.public.sqlserver.dts)
  • Re: Unicode Support
    ... if two Unicode strings are the same? ... UTF-16 is basically telling everyone "ok we all got to start ... character, and will likely support *both* endians. ... UTF-8 encodings are also easy to learn to ...
    (alt.lang.asm)
  • Re: Determining if a string is Unicode
    ... there's nothing magic about Unicode. ... where each character occupies 2 bytes, as opposed to a Single-Byte Character ... You could load up a string with rubbish, ... > INF file like so: ...
    (microsoft.public.vb.general.discussion)
  • Re: KANJD212
    ... >>Who decides the factors and what are their criteria, Unicode? ... But once a character is defined/get a codepoint in Unicode it ... standard modifies the codepoint of the kanji to a totally new ... I can use a code like JIS X0208 along with a font ...
    (sci.lang.japan)