Solved

VB SQL syntax

Posted on 2001-06-07
5
145 Views
Last Modified: 2010-05-02
Hi,

I want to sort an sql quey response using two sort keys.
What is the correct format?

So far I have

Select * from table where f > 1 order by 1

I also want to order by 2 too, what is the syntax?

eg

Select * from table where f > 1 order by 1 order by 2

Any help would be great.




0
Comment
Question by:wegwong
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 6162768
Select * from table where f > 1 order by 1,2

Cheers

0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6162855
Hi, you can also specify the sort order for fields by add ASC , DESC behind the sort key:

In Ascending Sort Order: Select * from table where f > 1 order by f ASC

In Descending Sort Order: Select * from table where f > 1 order by f DESC

Combination: Select * from table where f > 1 order by f, g DESC (g is assumed to another field)

_____________________________________________

As your sql: Select * from table where f > 1 order by 1 order by 2

Please take attention that we must sort the records according to a field name not to a field's value. So, it should be displayed something as:

Select * from table where f > 1 order by f, g (g is assumed to another field)

'Hope will help.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6162863
Select * Form [Your Table] Order By [Field 1], [Field 2] Desc;

Include the Desc keyword of you want descending order.

You can improve the speed of the response if you just select the fiels you need e.g.

Select [Field A], [Field B] Form [Your Table] Order By [Field 1], [Field 2] Desc;

You don't need the [] if your name conforms to the field naming rules and is not a keyword. But who is to say that your name won't become a keyword name in a future.

You need to find a copy of SQL server (and install with the Books On Line option) and get hold of the SQLBOL.exe which when extracted includes the complete syntax for SQL  and the SQL Server Manual.  You can download this file from Microsoft's site, but it took a long time to find. I think it is held under SQL server and then books on line.

You may also find SQLBOL.EXE if you download the developers version of SQL server which you are entiled to use if you have a copy of VB.

Hope this helps...






0
 
LVL 17

Expert Comment

by:inthedark
ID: 6162871
The full syntax is mind blowing....
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6163611
inthedark:
You may also find SQLBOL.EXE if you download the developers version of SQL server which you are entiled
to use if you have a copy of VB.

where did you get the developers version in a download?? That would be nice to have is MS lets you download it.  I looked on their site and they wanted about $500 for it.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

838 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