Solved

VB SQL syntax

Posted on 2001-06-07
5
137 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 142

Accepted Solution

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

Cheers

0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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
Comment Utility
The full syntax is mind blowing....
0
 
LVL 3

Expert Comment

by:jrspano
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now