Unix Technical Forum

Sorting - character after 'Z'?

This is a discussion on Sorting - character after 'Z'? within the SQL Server forums, part of the Microsoft SQL Server category; --> I'm using collation SQL_Latin1_General_CP1_CI_AS and I need to sort a varchar field. There are some elements, however, that I ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 09:07 AM
Duy Lam
 
Posts: n/a
Default Sorting - character after 'Z'?

I'm using collation SQL_Latin1_General_CP1_CI_AS and I need to sort a
varchar field. There are some elements, however, that I want to come
AFTER any alphabetic characters. Is there any character that sorts
after "Z"? In normal ASCII, there are various characters that would
sort after "Z" (e.g. "~"), but I can't seem to figure out what the case
would be in the SQL_Latin1_General_CP1_CI_AS collation. Any ideas?

thanks,
Duy Lam

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 09:07 AM
Simon Hayes
 
Posts: n/a
Default Re: Sorting - character after 'Z'?


"Duy Lam" <duylam@gmail.com> wrote in message
news:1119462033.433216.3880@f14g2000cwb.googlegrou ps.com...
> I'm using collation SQL_Latin1_General_CP1_CI_AS and I need to sort a
> varchar field. There are some elements, however, that I want to come
> AFTER any alphabetic characters. Is there any character that sorts
> after "Z"? In normal ASCII, there are various characters that would
> sort after "Z" (e.g. "~"), but I can't seem to figure out what the case
> would be in the SQL_Latin1_General_CP1_CI_AS collation. Any ideas?
>
> thanks,
> Duy Lam
>


Perhaps you can post a specific script to show what you want? Many
characters might sort after 'Z', as you said - maybe you should check out
ASCII(), CHAR(), UNICODE(), COLLATE and "Using Unicode Data" in Books
Online? If you can post something that others can copy and paste into Query
Analyzer, then there's a better chance that you'll get a useful answer.

http://www.aspfaq.com/etiquette.asp?id=5006

Simon


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 09:08 AM
Duy Lam
 
Posts: n/a
Default Re: Sorting - character after 'Z'?

Well, it's not so much there's a specific script I have that I need to
get working. I just want a way to enforce a certain order among rows.
For instance, let's say I have a table

T(someindex int, sortkey varchar(5), val int)

....and it's loaded with some data. for each row, the "sortkey" is a
field so that a user (who's using my app) can manually enforce an order
among "val"s. Normally it will be filled with some kind of alphanumeric
data.

I want to return the "val" column, but ordered by "sortkey". This, of
course, is easily obtained by running:

SELECT val FROM T ORDER BY sortkey

but for some rows, I may want to force certain "val"s to appear at the
end. One way, of course, is to set sortkey to "ZZZZZ" for those vals,
but there might be a chance that "ZZZZZ" is an actual value set by the
user. Thus I want some kind of character that is sorted even lower than
"Z" to guarantee that it comes after any possible alphanumeric entry
for "sortkey".

as i mentioned, in ASCII there are a number of characters that follow
'z', but I don't know any for the standard SQL_Latin1_General_CP1_CI_AS
collation.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 09:08 AM
Erland Sommarskog
 
Posts: n/a
Default Re: Sorting - character after 'Z'?

[posted and mailed, please reply in news]

Duy Lam (duylam@gmail.com) writes:
> I'm using collation SQL_Latin1_General_CP1_CI_AS and I need to sort a
> varchar field. There are some elements, however, that I want to come
> AFTER any alphabetic characters. Is there any character that sorts
> after "Z"? In normal ASCII, there are various characters that would
> sort after "Z" (e.g. "~"), but I can't seem to figure out what the case
> would be in the SQL_Latin1_General_CP1_CI_AS collation. Any ideas?


Looks like you have to learn Icelandic. :-) The script below helps you
out:

CREATE TABLE slafs (a int IDENTITY,
b AS char(a),
c int NOT NULL)
go
INSERT slafs (c) SELECT TOP 255 OrderID FROM Northwind..Orders
go
SELECT * FROM slafs ORDER BY b
SELECT * FROM slafs ORDER BY b COLLATE SQL_Latin1_General_CP1_CI_AS
go
DROP TABLE slafs


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:58 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com