order by problem

order by problem

Post by Cristiano Largh » Sat, 29 Sep 2001 19:43:04



Hi to everybody,


Example:



select top 1 *
from miodb.dbo.miatabella

How can I do this?

Thanks a lot
Cristiano Larghi

 
 
 

order by problem

Post by eee » Sun, 30 Sep 2001 01:12:59


Use sp_executesql






--
rw


> Hi to everybody,


> Example:



> select top 1 *
> from miodb.dbo.miatabella

> How can I do this?

> Thanks a lot
> Cristiano Larghi


 
 
 

order by problem

Post by BP Margoli » Sun, 30 Sep 2001 03:18:51


Cristiano,

Check out the "orderbyvariable" entry in the SQL Server FAQ at
www.sqlserverfaq.com

-------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.


> Hi to everybody,


> Example:



> select top 1 *
> from miodb.dbo.miatabella

> How can I do this?

> Thanks a lot
> Cristiano Larghi

 
 
 

order by problem

Post by Pame » Sun, 30 Sep 2001 04:01:05


Use dynamic SQL.





                    + ' from master..sysdatabases '
                    + ' order by '



> Hi to everybody,


> Example:



> select top 1 *
> from miodb.dbo.miatabella

> How can I do this?

> Thanks a lot
> Cristiano Larghi

 
 
 

order by problem

Post by CoolBoo » Sun, 30 Sep 2001 05:32:46





Jason


> Hi to everybody,


> Example:



> select top 1 *
> from miodb.dbo.miatabella

> How can I do this?

> Thanks a lot
> Cristiano Larghi

 
 
 

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

Hi all,

I hope someone might be able to help me with this query.

I have a table with several values in it, say:

Item_ID, Item_Type, Item_Desc, Item_Price, Date_Added

And this table is used to populate a form.

The dates are stored in the form: dd/mm/yyyy - e.g. 01/03/2002 (1st March
2002).

I want to be able to order the recordset by the Date_Added value in the
form - but of course, this doesn't work because of the date field cannot be
ordered correctly (11/03/2002 would come BEFORE 05/03/2002, or even before
07/09/2009).

So, I've decided to try using the T-SQL functions Day(), Month(), Year() to
extract the necessary fields (I could have converted the Date_Added column
to char and used mid and substring). This works great. Only... since I'm
using a SELECT DISTINCT - and I have functions in the ORDER BY, I have to
put the ORDER BY clauses in the SELECT clause - meaning that I have more
information than I need passed back to the form:

SELECT DISTINCT Item_ID... Date_Added, Day(Date_Added), Month(Date_Added),
Year(Date_Added)
...
ORDER BY Item_Type, Day(Date_Added), Month(Date_Added), Year(Date_Added)

And it simply returns the fields in the SELECT clause. However, I DON'T WANT
the functions returned. (Basically, there was a bug in the form that meant
that the date_added field wasn't being ordered correctly). I'd still like to
return the Date_Added field as it should be - but I'd like to order the
results using the Day(), Month() and Year() functions without them appearing
as part of the recordset/returned data.

Is there a simple way to do this within T-SQL?

Thanks in advance!

Mike

--

Liddle Feesh
 '  O 0 o <"//><  ' o'^
(Remove UNDERPANTS to reply)

2. Help needed selecting records from table randomly.

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

4. Invoking D3/Nt from a command line

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

6. CTT*.tmp files in c:\temp grows until 'Unable to write to file buffer' error

7. Order By Question - Non alphabetical order

8. How can I invoke function ?

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

10. ORDER BY upper case first in alphabetical sort order

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

12. Deleting Orders and Order Details Fast

13. Order result from SP in random order