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
DavidCollation is an attribute of column in the table (which inherits from the da
tabase if you don't
specify when you create the table). Anyhow, below seems to sort correctly. C
an 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/
"David DB" <er_fortsatt@.hotmail.com> wrote in message news:%23SSL2NOVGHA.196@.TK2MSFTNGP10.p
hx.gbl...
> 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
>|||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...
> 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/
>
> "David DB" <er_fortsatt@.hotmail.com> wrote in message
> news:%23SSL2NOVGHA.196@.TK2MSFTNGP10.phx.gbl...
>|||The purpose of my post was not to suggest you add COLLATE to every query, bu
t 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 COLL
ATE 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/
"David DB" <er_fortsatt@.hotmail.com> wrote in message
news:%23V$9JSWVGHA.5588@.TK2MSFTNGP09.phx.gbl...
> Hi,
> This works, but I dont want to set the collate sequence on every select st
atement.
> 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 i
n message
> news:OPaEtnOVGHA.4384@.tk2msftngp13.phx.gbl...
>|||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...
> 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/
>
> "David DB" <er_fortsatt@.hotmail.com> wrote in message
> news:%23V$9JSWVGHA.5588@.TK2MSFTNGP09.phx.gbl...
>|||> How can I make a script that sets all field collations to database default
?
Use:
ALTER TABLE ... ALTER COLUMN... COLLATE ...
This has to be done once per table and column. Be aware that you have to dro
p 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/
"David DB" <er_fortsatt@.hotmail.com> wrote in message news:OaIzaqWVGHA.1740@.TK2MSFTNGP14.ph
x.gbl...
> Thanks,
> I found that with the tabales already present the collation order had to b
e 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 i
n message
> news:ORGvXZWVGHA.1688@.TK2MSFTNGP11.phx.gbl...
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment