Query Japanese Text in an NVarChar?
am 15.04.2008 22:06:19 von rowe_newsgroups
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]
Re: Query Japanese Text in an NVarChar?
am 16.04.2008 05:36:44 von Tom van Stiphout
On Tue, 15 Apr 2008 13:06:19 -0700 (PDT), rowe_newsgroups
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]
Re: Query Japanese Text in an NVarChar?
am 16.04.2008 13:12:06 von rowe_newsgroups
On Apr 15, 11:36 pm, Tom van Stiphout wrote:
> On Tue, 15 Apr 2008 13:06:19 -0700 (PDT), rowe_newsgroups
>
> 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]