Solved

VB SQL syntax

Posted on 2001-06-07
5
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 52

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

739 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