ORder by 
Author Message
 ORder by
Can you do an order by  to where it is ascending, but I want nulls to be at
the bottom instead at the top.

Dianna



Tue, 09 Dec 2003 05:58:36 GMT
 ORder by

You could include the column you are ordering by twice in the select
statement. In one of them replace the column with the isnull(column,
99999999) or some other artifically high number. Order By the column with
the ISNULL() function, but reference the other one in code.

--
David Gugick
Intrinsic Design, Inc.
Coefficient - Database Analysis for Microsoft SQL Server
http://www.idisoft.com



Tue, 09 Dec 2003 06:47:10 GMT
 ORder by
Check out my Dec 1999 article on this topic in SQL Server Professional:

http://www.pinnaclepublishing.com/SQ/SQmag.nsf/0/E217143728E982B88525...
8B877

--
   Tom

----------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCT
Columnist, SQL Server Professional

Toronto, ON Canada
www.pinnaclepublishing.com/sql
www.apress.com
---
Can you do an order by  to where it is ascending, but I want nulls to be at
the bottom instead at the top.

Dianna



Tue, 09 Dec 2003 06:47:01 GMT
 ORder by
Hi,

I have several parameters passed to a stored procedure. Due to what value
the parameters have I would like the sortorder to be different by using the
Order by clause. How is this done in a smart way? Now the stored procedure
contains alot of code.

Example:

                            from table
                            order by a, b, c

                            from table
                            order by c, b, a
etc.

Regards,
Wenche



Mon, 15 Dec 2003 15:32:18 GMT
 ORder by
Use dynamic SQL to build the query and use sp_executesql to execute it.

--
Tony Rogerson SQL Server MVP
Independant Consultant
Torver Computer Consultants Ltd
www.sql-server.co.uk [UK Independent SQL Server User Group; FAQ; KBase
etc..]


Quote:
> Hi,

> I have several parameters passed to a stored procedure. Due to what value
> the parameters have I would like the sortorder to be different by using
the
> Order by clause. How is this done in a smart way? Now the stored procedure
> contains alot of code.

> Example:

>                             from table
>                             order by a, b, c

>                             from table
>                             order by c, b, a
> etc.

> Regards,
> Wenche



Mon, 15 Dec 2003 15:50:55 GMT
 ORder by
try...

select a,b,c
from tablename

 when 1 then a
 when 0 then c end,
 b,

 when 1 then c
 when 0 then a end

hth.

-oj


Quote:
> Hi,

> I have several parameters passed to a stored procedure. Due to what value
> the parameters have I would like the sortorder to be different by using
the
> Order by clause. How is this done in a smart way? Now the stored procedure
> contains alot of code.

> Example:

>                             from table
>                             order by a, b, c

>                             from table
>                             order by c, b, a
> etc.

> Regards,
> Wenche



Mon, 15 Dec 2003 16:15:14 GMT
 
 [ 6 post ] 

 Relevant Pages 

1. ORDER BY without SELECT clause (order by function)

2. Multiple Tables DTS Order- How do I make them run in Specified order (not Alphbet)

3. Q: Prepackaged Sales Order Processing solution for Mail-Order

4. Multiple Tables DTS Order- How do I make them run in Specified order (not Alphbet)

5. Converting a database from dictionary case insensitive sort order to binary sort order

6. Order By Question - Non alphabetical order

7. Custom Rollup Formula / Pass Order / Solve Order

8. Adding the total sale for each order based on order detail

9. ORDER BY upper case first in alphabetical sort order

10. Converting a database from dictionary case insensitive sort order to binary sort order

11. Deleting Orders and Order Details Fast

12. Select from users order by count of orders..


 
Powered by phpBB® Forum Software