[MSSQL] Order By op taal-afhankelijke manier

Pagina: 1
Acties:

  • Mephix
  • Registratie: Augustus 2001
  • Laatst online: 25-11-2025
Er is binnen Oracle de mogelijkheid om een sql sessie var NLS_SORT op bijvoorbeeld SWEDISH te zetten. Daarmee komt een ORDER BY selectie terug op de manier zoals het Zweedse alfabet is samengesteld.

Nu zoek ik een vergelijkbare manier in MSSQL. Met andere woorden, het kunnen ordenen van selecties op een taalafhankelijke manier.

Een voorbeeldje:

Engels / Amerikaans = A, Å, Ä, B, C ... N, O, Ö, P ... Z
Zweeds = A ... Z, Å, Ä, Ö

Het makkelijkste zou zijn als hier een functie voor is binnen MSSQL, waarmee ik in de query op kan geven volgens welke taal de boel gesorteerd moet worden. Vergelijkbaar dus met de NLSSORT van Oracle.

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

Zoek eens op 'COLLATE' in de online help ;)

Professionele website nodig?


  • P_de_B
  • Registratie: Juli 2003
  • Niet online
Je kunt collations gebruiken.

http://msdn.microsoft.com...tsqlref/ts_ca-co_5z55.asp

edit:

curry :(

[ Voor 12% gewijzigd door P_de_B op 11-10-2004 11:07 ]

Oops! Google Chrome could not find www.rijks%20museum.nl


  • Mephix
  • Registratie: Augustus 2001
  • Laatst online: 25-11-2025
Die had ik idd al gevonden, maar dat is enkel voor de hele server ? Hier draaien meer applicaties op en niet allen Zweeds.

Tenminste, voor zover ik kon zien kan ik dit niet bv. per query opgeven.

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

Volgens mijn online help (entry 'Collation Precedence') is dit toch een geldige query anders:
SQL:
1
2
3
SELECT (CASE WHEN id > 10 THEN GreekCol ELSE LatinCol END) 
COLLATE Latin1_General_CI_AS 
FROM TestTab

:)

Voor de volledigheid:
The COLLATE clause can be specified at several levels, including the following:

1. Creating or altering a database.
You can use the COLLATE clause of the CREATE DATABASE or ALTER DATABASE statement to specify the default collation of the database. You can also specify a collation when you create a database using SQL Server Enterprise Manager. If you do not specify a collation, the database is assigned the default collation of the SQL Server instance.

2. Creating or altering a table column.
You can specify collations for each character string column using the COLLATE clause of the CREATE TABLE or ALTER TABLE statement. You can also specify a collation when you create a table using SQL Server Enterprise Manager. If you do not specify a collation, the column is assigned the default collation of the database.

You can also use the database_default option in the COLLATE clause to specify that a column in a temporary table use the collation default of the current user database for the connection instead of tempdb.

3. Casting the collation of an expression.
You can use the COLLATE clause to cast a character expression to a certain collation. Character literals and variables are assigned the default collation of the current database. Column references are assigned the definition collation of the column. For the collation of an expression, see Collation Precedence.

[ Voor 79% gewijzigd door curry684 op 11-10-2004 11:13 ]

Professionele website nodig?


  • P_de_B
  • Registratie: Juli 2003
  • Niet online
Je kunt ook gewoon

SELECT *
FROM Tabel COLLATE [whatever] gebruiken

edit:

ik hou er wel mee op.....

[ Voor 23% gewijzigd door P_de_B op 11-10-2004 11:11 ]

Oops! Google Chrome could not find www.rijks%20museum.nl


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

P_de_B schreef op 11 oktober 2004 @ 11:11:
edit:

ik hou er wel mee op.....
Knuf O+ Ik ga nu roken, mag jij het vanaf nu overnemen ;)

Professionele website nodig?


  • P_de_B
  • Registratie: Juli 2003
  • Niet online
curry684 schreef op 11 oktober 2004 @ 11:14:
[...]

Knuf O+ Ik ga nu roken, mag jij het vanaf nu overnemen ;)
offtopic:
:> '

dacht dat het wel duidelijk was nu, enne roken maakt je impotent ;)

Oops! Google Chrome could not find www.rijks%20museum.nl


  • Mephix
  • Registratie: Augustus 2001
  • Laatst online: 25-11-2025
P_de_B schreef op 11 oktober 2004 @ 11:11:
Je kunt ook gewoon

SELECT *
FROM Tabel COLLATE [whatever] gebruiken
Is dit iets wat je getest hebt ? Ik krijg namelijk niets anders dan Invalid syntax near the keyword 'COLLATE'. Heb de query al op verschillende manieren geprobeerd (eerst de FROM clause en dan COLLATE of andersom), maar COLLATE is toch iets wat (in de query analizer althans) voor errors zorgt.

  • Mephix
  • Registratie: Augustus 2001
  • Laatst online: 25-11-2025
Hmm.. zo moet ie zijn:

SELECT *
FROM <tabel>
ORDER BY <colom>
COLLATE SQL_SwedishStd_Pref_Cp1_CI_AS

Of een andere collate ofcoz...

Zie
http://msdn.microsoft.com...tsqlref/ts_ca-co_5ell.asp
voor een lijst met alle collation names.

[ Voor 6% gewijzigd door Mephix op 11-10-2004 12:12 ]

Pagina: 1