Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL ORDER BY condition 1

Status
Not open for further replies.

acnovice

Programmer
Jan 27, 2005
100
US
Hi,

I want to sorting 2 columns in order but only one column is sorted. I need someone's help to figure it out.

Here is my SQL statement.

Code:
SELECT QNo & [QNoRev] AS QRev, InquiryLog.InqDate, InquiryLog.ProducType, InquiryLog.InpuType, InquiryLog.TotalWatt, InquiryLog.OutputType, 
.....
FROM InquiryLog
WHERE ((((InquiryLog.AccMgr) Like "11")) AND (((InquiryLog.Status) Like "Hot") OR ((InquiryLog.Status) Like "Active") OR ((InquiryLog.Status) Like "Low")) AND (((InquiryLog.BallsIn) Like "AM") OR ((InquiryLog.BallsIn) Like "PM") OR ((InquiryLog.BallsIn) Like "Customer")))

ORDER BY ((InquiryLog.Status) Like "Hot"), ((InquiryLog.Status) Like "Active"), ((InquiryLog.Status) Like "Low") AND ((InquiryLog.BallsIn) Like "AM"), ((InquiryLog.BallsIn) Like "PM"), ((InquiryLog.BallsIn) Like "Customer");
I want the order like below.

AccountMgr Status BallsIn
11 Hot AM
11 Hot PM
11 Hot Customer
11 Active AM
11 Low AM
11 Low PM
11 Low Customer

AccountMgr is 11
AND sorting order of status is Hot-Active-Low
AND order of BallsIn is AM-PM-Customer.

Appreciate your help.
 
You may try this:
ORDER BY Switch(InquiryLog.Status="Hot",1, InquiryLog.Status="Active",2, InquiryLog.Status="Low",3, True,9), Switch(InquiryLog.BallsIn="AM",1, InquiryLog.BallsIn="PM",2, InquiryLog.BallsIn="Customer",3, True,9);


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

This is what I want exactly. Works perfect.
Can you recommend any link or books for sql statement ?
I'm spending a lot of time to write SQL statement and face to difficulty.

Thank you so much!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top