Home All Groups Group Topic Archive Search About
Author
3 Feb 2006 11:23 AM
Xavier
hello,
i want to find the rows in which field1 did not mach field2 .. (problem with
special caracters)
i have a table which is  a result of a insert .....
In the table are id and  2 fields of type Varchar(50)

How can i compare if in the table the two fields are identical. I have
problem in case of special caracters.

MyTable with id,field1 and field2

1 john john ok
2 Mueller  Müller -> *problem!!!
3 Röster  Roester -> problem!!!!
4 Max Otto

i want to list only the row where the content is not "identical"
4 Max Otto 
the other records are not to be listed because (ue=ü oe=ö)

how to configure the where conditionl - the problems are with the special
german caracters
ö->oe
Ü->ue ....

thanks

Author
3 Feb 2006 11:46 AM
Razvan Socol
Hi, Xavier

You need to use a german collation when you create the table or in the
query. For example:

CREATE TABLE MyTable (
    ID int PRIMARY KEY,
    field1 nvarchar(50) COLLATE German_PhoneBook_CI_AI NOT NULL,
    field2 nvarchar(50) COLLATE German_PhoneBook_CI_AI NOT NULL
)

INSERT INTO MyTable VALUES (1, 'john','john')
INSERT INTO MyTable VALUES (2, 'Mueller','Müller')
INSERT INTO MyTable VALUES (3, 'Röster','Roester')
INSERT INTO MyTable VALUES (4, 'Max','Otto')

SELECT * FROM MyTable WHERE field1<>field2
-- you will only 1 row (Max / Otto)

SELECT * FROM MyTable WHERE field1<>field2 COLLATE Latin1_General_CI_AS
-- you will get 3 rows

SELECT * FROM MyTable WHERE field1<>field2 COLLATE
German_PhoneBook_CI_AI
-- you will get 1 row, even if the table would not be created using the
german collation

DROP TABLE MyTable

Note: In SQL Server, collations can be configured at several levels:
- the default collation for the entire server (instance)
- the default collation of the database
- the collation of the column in some table

If you change the default collation only for some databases, but not
for the server you may get "Cannot resolve collation conflict for equal
to operation." errors, for example when you join a normal table with a
temporary table on a character column.

You should:
(a) use the COLLATE clause in the queries
or:
(b) use the same default collation for all databases and for the
server.

Razvan
Author
6 Feb 2006 1:19 PM
Xavier
Hello Razan,

it is great,
thanks


Show quote
"Razvan Socol" wrote:

> Hi, Xavier
>
> You need to use a german collation when you create the table or in the
> query. For example:
>
> CREATE TABLE MyTable (
>     ID int PRIMARY KEY,
>     field1 nvarchar(50) COLLATE German_PhoneBook_CI_AI NOT NULL,
>     field2 nvarchar(50) COLLATE German_PhoneBook_CI_AI NOT NULL
> )
>
> INSERT INTO MyTable VALUES (1, 'john','john')
> INSERT INTO MyTable VALUES (2, 'Mueller','Müller')
> INSERT INTO MyTable VALUES (3, 'Röster','Roester')
> INSERT INTO MyTable VALUES (4, 'Max','Otto')
>
> SELECT * FROM MyTable WHERE field1<>field2
> -- you will only 1 row (Max / Otto)
>
> SELECT * FROM MyTable WHERE field1<>field2 COLLATE Latin1_General_CI_AS
> -- you will get 3 rows
>
> SELECT * FROM MyTable WHERE field1<>field2 COLLATE
> German_PhoneBook_CI_AI
> -- you will get 1 row, even if the table would not be created using the
> german collation
>
> DROP TABLE MyTable
>
> Note: In SQL Server, collations can be configured at several levels:
> - the default collation for the entire server (instance)
> - the default collation of the database
> - the collation of the column in some table
>
> If you change the default collation only for some databases, but not
> for the server you may get "Cannot resolve collation conflict for equal
> to operation." errors, for example when you join a normal table with a
> temporary table on a character column.
>
> You should:
> (a) use the COLLATE clause in the queries
> or:
> (b) use the same default collation for all databases and for the
> server.
>
> Razvan
>
>
Author
3 Feb 2006 12:30 PM
Tony Scott
Xavier,

A simple solution, but maybe too simple for enormous sets of data, is to use
the REPLACE function to change one of the columns to match the other. Ref BoL.

Tony

Show quote
"Xavier" wrote:

> hello,
> i want to find the rows in which field1 did not mach field2 .. (problem with
> special caracters)
> i have a table which is  a result of a insert .....
> In the table are id and  2 fields of type Varchar(50)
>
> How can i compare if in the table the two fields are identical. I have
> problem in case of special caracters.
>
> MyTable with id,field1 and field2
>
> 1 john john ok
> 2 Mueller  Müller -> *problem!!!
> 3 Röster  Roester -> problem!!!!
> 4 Max Otto
>
> i want to list only the row where the content is not "identical"
> 4 Max Otto 
> the other records are not to be listed because (ue=ü oe=ö)
>
> how to configure the where conditionl - the problems are with the special
> german caracters
> ö->oe
> Ü->ue ....
>
> thanks
>
>
>
>
>
>

AddThis Social Bookmark Button