Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

what comes after 'Z'? (for varchar order by)

Posted on 2008-06-13
3
Medium Priority
?
227 Views
Last Modified: 2008-06-20
I've been hunting around for a character to put at the beginning of a varchar field that would cause it to alphabetize at the end of the list in an order by.  The field is defined as:
[MyField] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

And everything I have tried that comes after 'z' (lower case, which comes after upper case using an ascii table) gets sorted to the top instead of the bottom.  This includes the tilde, and broken and unbroken pipe character, both curly braces, and a couple of extended set characters way down on the list.

Thanks for any help-
0
Comment
Question by:ottenm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 21782156
Hmm, odd, those apparently should work.

If you don't care what the char looks like, I suggest CHAR(255).
0
 

Author Comment

by:ottenm
ID: 21782196
I thought so, too.  

The 255 works, but it is pretty ugly (hence the attempts with tilde, etc.).  I could code around it, but would prefer to find out why it's happening.  Maybe something with the COLLATE attribute?
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 21782348
True, it's ugly.

You could make the main query a sub-query, with a TOP 100 PERCENT to allow the ORDER BY in the subquery, then do a replace in an outer query to get rid of the CHAR(255) -- yuck.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question