Solved

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

Posted on 2008-06-13
3
225 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 69

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 69

Accepted Solution

by:
Scott Pletcher earned 500 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Report 8 27
t-sql left join 2 34
VB.Net CLR Assembly type Datatable into SQL 8 24
SQL Query 20 23
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

738 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