Solved

VB SQL syntax

Posted on 2001-06-07
5
142 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
ID: 6162768
Select * from table where f > 1 order by 1,2

Cheers

0
 
LVL 50

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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