Groups | Blog | Home
all groups > sql server programming > march 2006 >

sql server programming : Norwegian collation


David DB
3/31/2006 6:51:55 PM
Hi,

When I order by a field the sorting is wrong for Norwegian.

The Å comes before the A for example.

I have tried different collation settings of the database, but cannot find
the correct one.

Anyone ?

Using SQL 2005/SQL 2000

David

Tibor Karaszi
3/31/2006 7:38:33 PM
Collation is an attribute of column in the table (which inherits from the database if you don't
specify when you create the table). Anyhow, below seems to sort correctly. Can you post a repro
which doesn't?

CREATE TABLE #t(c char(2))
INSERT INTO #t VALUES('a')
INSERT INTO #t VALUES('b')
INSERT INTO #t VALUES('z')
INSERT INTO #t VALUES('A')
INSERT INTO #t VALUES('B')
INSERT INTO #t VALUES('Z')
INSERT INTO #t VALUES('å')
INSERT INTO #t VALUES('ä')
INSERT INTO #t VALUES('ö')
INSERT INTO #t VALUES('Å')
INSERT INTO #t VALUES('Ä')
INSERT INTO #t VALUES('Ö')
INSERT INTO #t VALUES('ü')
INSERT INTO #t VALUES('Ü')
INSERT INTO #t VALUES('vb')
INSERT INTO #t VALUES('Va')
INSERT INTO #t VALUES('Wb')
INSERT INTO #t VALUES('wa')


SELECT * FROM #t ORDER BY c COLLATE Danish_Norwegian_CI_AI


--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/


[quoted text, click to view]
David DB
4/1/2006 12:00:00 AM
Hi,

This works, but I dont want to set the collate sequence on every select
statement.

Tried to set it on the database, but with no luck.

Any ideas ?

David

"Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote in
message news:OPaEtnOVGHA.4384@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Tibor Karaszi
4/1/2006 12:00:00 AM
The purpose of my post was not to suggest you add COLLATE to every query, but to prove that the
collation in question does indeed sort correctly. Below is a revised version of that script which
creates a database with a Norwegian collation and does a select without COLLATE in the order by. It
still sorts correctly. This is why I asked for a repro...

SET NOCOUNT ON
CREATE DATABASE x COLLATE Danish_Norwegian_CI_AI
GO

USE x
GO


CREATE TABLE t(c char(2))
INSERT INTO t VALUES('a')
INSERT INTO t VALUES('b')
INSERT INTO t VALUES('z')
INSERT INTO t VALUES('A')
INSERT INTO t VALUES('B')
INSERT INTO t VALUES('Z')
INSERT INTO t VALUES('å')
INSERT INTO t VALUES('ä')
INSERT INTO t VALUES('ö')
INSERT INTO t VALUES('Å')
INSERT INTO t VALUES('Ä')
INSERT INTO t VALUES('Ö')
INSERT INTO t VALUES('ü')
INSERT INTO t VALUES('Ü')
INSERT INTO t VALUES('vb')
INSERT INTO t VALUES('Va')
INSERT INTO t VALUES('Wb')
INSERT INTO t VALUES('wa')


SELECT * FROM t ORDER BY c


--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/


[quoted text, click to view]
David DB
4/1/2006 12:00:00 AM
Thanks,

I found that with the tabales already present the collation order had to be
set to default. New tables inherits the new collation.

How can I make a script that sets all field collations to database default ?

David

"Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote in
message news:ORGvXZWVGHA.1688@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Tibor Karaszi
4/1/2006 12:00:00 AM
[quoted text, click to view]

Use:
ALTER TABLE ... ALTER COLUMN... COLLATE ...

This has to be done once per table and column. Be aware that you have to drop indexes for the column
(and possible constraints etc, see Books Online). I haven't seen any script that automates this,
perhaps you'll find such by Googling a bit.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/


[quoted text, click to view]
AddThis Social Bookmark Button