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 2012 Forums
 Transact-SQL (2012)
 WHERE IN clause with non-English text fails

Author  Topic 

LexOccam
Starting Member

1 Post

Posted - 2013-04-15 : 18:08:50
I have a simple table with { Name nvarchar(50), ID (int) } columns in an English (EN-Us) database.

A tester inserts the following Names: ??, öÄéß, ?e?µ

I would like to know why a SELECT statement with a WHERE IN clause only yields one result, even though all values are specified as nvarchar. Thank you.

Example query:

Declare @setOfIds nvarchar(200) = N'''??'',''öÄéß'',''?e?µ'''
Declare @strSql nvarchar(1024)
Set @strSql = N'SELECT Name, ID from MyTable WHERE Name IN (' + @setOfIds + N')'
EXEC (@strSql)

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-16 : 00:19:04
-- see this illustration... working fine
CREATE TABLE Names (name NVARCHAR(100))
INSERT INTO Names
SELECT '??'union all
SELECT 'öÄéß' union all
SELECT '?e?µ'
--I would like to know why a SELECT statement with a WHERE IN clause only yields one result, even though all values are specified as nvarchar.

Declare @setOfIds nvarchar(200) = N'''??'',''öÄéß'',''?e?µ'''
Declare @strSql nvarchar(1024)
Set @strSql = N'SELECT Name from Names WHERE Name IN (' + @setOfIds + N')'
EXEC (@strSql)

/*Output:
Name
----------------------------------------------------------------------------------------------------
??
öÄéß
?e?µ
*/

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-16 : 02:28:58
First check if datatype of Name field is nvarchar

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -