Solved

VB SQL syntax

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

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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

623 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