Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Unicode Query

Author  Topic 

Nick
Posting Yak Master

155 Posts

Posted - 2004-01-26 : 12:08:44
Hello-

I'm having a problem with a simple query, and I'm really not sure why. I have a field defined as nvarchar. When I do the following query in the query analyzer:

select top 1 tbLast from tblPeople

I get the following result

Ñáðôïðïýëïõ

Now if I do this query:

select top 1 tbLast from tblPeople
WHERE tbLast LIKE '%Ñáðôïðïýëïõ%'

Nothing gets returned. I would expect I would get the same result as above. Is there something I'm missing when working with Unicode?

Thanks-
Nick

(Note, the result did not render properly in the forum, but for reference purposes it contains Greek characters.

nr
SQLTeam MVY

12543 Posts

Posted - 2004-01-26 : 12:14:50
try
select top 1 tbLast from tblPeople
WHERE tbLast LIKE N'%Ñáðôïðïýëïõ%'

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2004-01-26 : 12:14:52
You need to make sure your unicode literal strings have an N in front of them, otherwise the characters not included in the server's (or is it the OS's?) default character set will get down-converted (probably to question marks).


select top 1 tbLast from tblPeople
WHERE tbLast LIKE N'%Ñáðôïðïýëïõ%'


Gah! Two seconds!
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-01-26 : 12:16:55
lol.
I went back to edit in a comment about convertion straight after hitting submit and Arnold was already there.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Nick
Posting Yak Master

155 Posts

Posted - 2004-01-26 : 12:24:17
OK, that took care of that.

Now for the real problem (as that part of the problem was me just trying to debug the original problem)

I pass the field using a sproc. The sproc in turn uses dynamic sql to put together a rather complex query. If instead of exec'ing the dynamic sql I instead select it, my query ends up looking like the characters aren't in unicode.

Does this make any sense?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-01-26 : 12:34:48
You have to use unicode everywhere.
The exec'd string, parameter received, parameter passed, all strings used to concatenate, ...

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -