Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Order By clause

 
   Database Help (Home) -> MSEQ RSS
Next:  Paste Append into Access 2007 from Excel 2007  
Author Message
ChicagoPete

External


Since: Aug 07, 2008
Posts: 5



(Msg. 1) Posted: Thu Dec 11, 2008 8:41 am
Post subject: Order By clause
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

I have a stored procdeure that runs to populate a pick-list based on several
criteria. It is set to Order By ascending by default. I have a end-user that
would like the list to return one particular value at the top each time and
then by ascending order. How do I Order By a text value then ascending?

Example:Fat,Normal,Thin,Ugly
Should return: Normal,Fat,Thin,Ugly

It should always return 'Normal' in the first position then sort the
remaining values by ascending order.

Thanks for any help...

 >> Stay informed about: Order By clause 
Back to top
Login to vote
Russell Fields

External


Since: Jan 10, 2008
Posts: 608



(Msg. 2) Posted: Thu Dec 11, 2008 12:39 pm
Post subject: Re: Order By clause [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Well, you could do something like:

....
ORDER BY
CASE (Criteria)
WHEN ('Normal') THEN 0
ELSE 1
END,
Criteria

The extra sorting column of 0 or 1 will force the 0's to the top, but keep
alphabetic order within the 0 and 1 groups.

RLF


"ChicagoPete" wrote in message

>I have a stored procdeure that runs to populate a pick-list based on
>several
> criteria. It is set to Order By ascending by default. I have a end-user
> that
> would like the list to return one particular value at the top each time
> and
> then by ascending order. How do I Order By a text value then ascending?
>
> Example:Fat,Normal,Thin,Ugly
> Should return: Normal,Fat,Thin,Ugly
>
> It should always return 'Normal' in the first position then sort the
> remaining values by ascending order.
>
> Thanks for any help...

 >> Stay informed about: Order By clause 
Back to top
Login to vote
ChicagoPete

External


Since: Aug 07, 2008
Posts: 5



(Msg. 3) Posted: Thu Dec 11, 2008 12:39 pm
Post subject: Re: Order By clause [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hey Russell,
Thanks for the quick reply and solution! Never thought of using a CASE with
an Order By, always thought the Order By was cut and dry - ASC or DESC.

-Pete

"Russell Fields" wrote:

> Well, you could do something like:
>
> ....
> ORDER BY
> CASE (Criteria)
> WHEN ('Normal') THEN 0
> ELSE 1
> END,
> Criteria
>
> The extra sorting column of 0 or 1 will force the 0's to the top, but keep
> alphabetic order within the 0 and 1 groups.
>
> RLF
>
>
> "ChicagoPete" wrote in message
>
> >I have a stored procdeure that runs to populate a pick-list based on
> >several
> > criteria. It is set to Order By ascending by default. I have a end-user
> > that
> > would like the list to return one particular value at the top each time
> > and
> > then by ascending order. How do I Order By a text value then ascending?
> >
> > Example:Fat,Normal,Thin,Ugly
> > Should return: Normal,Fat,Thin,Ugly
> >
> > It should always return 'Normal' in the first position then sort the
> > remaining values by ascending order.
> >
> > Thanks for any help...
>
>
 >> Stay informed about: Order By clause 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Cannot Reference Named Column in WHERE Clause - SQL Server 2005. I have a view defined for a database. Part of the query is: SELECT dbo.GL7PROJECTS.PROJECTID AS JURISDICTION I have not problem using JURISDICTION in the ORDER BY clause, but when I try to use it in a WHERE clause (e.g., WHERE..

Formatting numeric fields in select-clause - This is propably a very simple question, but I can“t seem to find the answer to it in the documentation. I want to format a numeric field so the result is right justified and zero-filled. ex select 1 will give the result 01 How do I manage this..

index on a view - Hello, I have a table (TAB) and A View with alias (VIEW) Table cod varchar 3 descr carchar 60 my view cod alias COd1 descr alias DES Now i need a index on view with key COD1 I can't create it. Can..

Creating an alias - I have an alias that can get very long because it maintains a information of where it came from. Is there a way to alias an alias? My first thought was: Declare @T1 varchar(128) Set T1 = 'MyAlias' .... Inner Join Table1 as @T1 This of course does no...

Simple Query problem - Sample table as follows Order ID Stock Code Status --------- ------- ------- 203 STK1 3 203 STK2 2 203 STK4 3 204 STK1 3 204 STK5 3 205 ..
   Database Help (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]