Unix Technical Forum

Query Japanese Text in an NVarChar?

This is a discussion on Query Japanese Text in an NVarChar? within the SQL Server forums, part of the Microsoft SQL Server category; --> I apologize if this has been covered ad nauseum, but I didn't see it in my search. Basically, in ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 09:32 PM
rowe_newsgroups
 
Posts: n/a
Default Query Japanese Text in an NVarChar?

I apologize if this has been covered ad nauseum, but I didn't see it
in my search.

Basically, in an nvarchar(150) column (called "Phrase" in the below
samples) I store both english text as well as japanese (the table is
for translations). What I'm having trouble with is querying the table
by the NVarChar field.

This works fine:

//////////////
SELECT *
FROM tbl_ShortPhrases
WHERE Phrase = 'Home'
//////////////

But when I try with japanese, nothing is returned:

/////////////
SELECT *
FROM tbl_ShortPhrases
WHERE Phrase = '再価格'
/////////////

I thought that the problem might be a conversion issue, so I tried the
following with no success:

/////////////
SELECT *
FROM tbl_ShortPhrases
WHERE Phrase = CONVERT(NVARCHAR, '再価格')
/////////////

Any help you can offer is appreciated!

Thanks,

Seth Rowe [MVP]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 05:08 PM
Tom van Stiphout
 
Posts: n/a
Default Re: Query Japanese Text in an NVarChar?

On Tue, 15 Apr 2008 13:06:19 -0700 (PDT), rowe_newsgroups
<rowe_email@yahoo.com> wrote:

Prefix literal unicode strings with N
For example in the AdventureWorks sample db:
select * from Person.Contact
where FirstName = N'???'

(I had used Character Map to select some Japanese character and use it
for a FirstName)

Unsure why CAST or CONVERT does not work. I would have expected the
same. Most likely following the rules of precedence your unicode is
first converted to ansi, then CONVERTed to unicode but by that time
it's too late.

-Tom.


>I apologize if this has been covered ad nauseum, but I didn't see it
>in my search.
>
>Basically, in an nvarchar(150) column (called "Phrase" in the below
>samples) I store both english text as well as japanese (the table is
>for translations). What I'm having trouble with is querying the table
>by the NVarChar field.
>
>This works fine:
>
>//////////////
>SELECT *
>FROM tbl_ShortPhrases
>WHERE Phrase = 'Home'
>//////////////
>
>But when I try with japanese, nothing is returned:
>
>/////////////
>SELECT *
>FROM tbl_ShortPhrases
>WHERE Phrase = '???'
>/////////////
>
>I thought that the problem might be a conversion issue, so I tried the
>following with no success:
>
>/////////////
>SELECT *
>FROM tbl_ShortPhrases
>WHERE Phrase = CONVERT(NVARCHAR, '???')
>/////////////
>
>Any help you can offer is appreciated!
>
>Thanks,
>
>Seth Rowe [MVP]

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 05:08 PM
rowe_newsgroups
 
Posts: n/a
Default Re: Query Japanese Text in an NVarChar?

On Apr 15, 11:36 pm, Tom van Stiphout <no.spam.tom7...@cox.net> wrote:
> On Tue, 15 Apr 2008 13:06:19 -0700 (PDT), rowe_newsgroups
>
> <rowe_em...@yahoo.com> wrote:
>
> Prefix literal unicode strings with N
> For example in the AdventureWorks sample db:
> select * from Person.Contact
> where FirstName = N'???'
>
> (I had used Character Map to select some Japanese character and use it
> for a FirstName)
>
> Unsure why CAST or CONVERT does not work. I would have expected the
> same. Most likely following the rules of precedence your unicode is
> first converted to ansi, then CONVERTed to unicode but by that time
> it's too late.
>
> -Tom.
>
> >I apologize if this has been covered ad nauseum, but I didn't see it
> >in my search.

>
> >Basically, in an nvarchar(150) column (called "Phrase" in the below
> >samples) I store both english text as well as japanese (the table is
> >for translations). What I'm having trouble with is querying the table
> >by the NVarChar field.

>
> >This works fine:

>
> >//////////////
> >SELECT *
> >FROM tbl_ShortPhrases
> >WHERE Phrase = 'Home'
> >//////////////

>
> >But when I try with japanese, nothing is returned:

>
> >/////////////
> >SELECT *
> >FROM tbl_ShortPhrases
> >WHERE Phrase = '???'
> >/////////////

>
> >I thought that the problem might be a conversion issue, so I tried the
> >following with no success:

>
> >/////////////
> >SELECT *
> >FROM tbl_ShortPhrases
> >WHERE Phrase = CONVERT(NVARCHAR, '???')
> >/////////////

>
> >Any help you can offer is appreciated!

>
> >Thanks,

>
> >Seth Rowe [MVP]


Ah,

Thanks Tom, it's now working just as I hoped. Amazing how one
character makes all the difference!

Thanks,

Seth Rowe [MVP]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:50 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com