ORDER BY IIF

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can you use an IIF statement in an ORDER BY statement in SQL?

Trying to change the order depending on the if statement?
 
It would take less time to try it this than to post the question in a news
group.

Open Northwind and create a query with this SQL
SELECT Employees.*
FROM Employees
ORDER BY IIf([LastName] Like "D*",[LastName],"A");
 
Thanks for this, worked fine but didn't resolve my problem. I have a sort
order of [No of Rides] desc, [Last Name] Desc, however when the [No of Rides]
= 0 I want the sort order to swap to [No of Rides] desc, [Last Name] Asc.

Can it be done?

Duane Hookom said:
It would take less time to try it this than to post the question in a news
group.

Open Northwind and create a query with this SQL
SELECT Employees.*
FROM Employees
ORDER BY IIf([LastName] Like "D*",[LastName],"A");

--
Duane Hookom
MS Access MVP

Paul Dennis said:
Can you use an IIF statement in an ORDER BY statement in SQL?

Trying to change the order depending on the if statement?
 
Please respond with some sample records and the desired output.

--
Duane Hookom
MS Access MVP

Paul Dennis said:
Thanks for this, worked fine but didn't resolve my problem. I have a sort
order of [No of Rides] desc, [Last Name] Desc, however when the [No of
Rides]
= 0 I want the sort order to swap to [No of Rides] desc, [Last Name] Asc.

Can it be done?

Duane Hookom said:
It would take less time to try it this than to post the question in a
news
group.

Open Northwind and create a query with this SQL
SELECT Employees.*
FROM Employees
ORDER BY IIf([LastName] Like "D*",[LastName],"A");

--
Duane Hookom
MS Access MVP

Paul Dennis said:
Can you use an IIF statement in an ORDER BY statement in SQL?

Trying to change the order depending on the if statement?
 
Sorted it now. converted the [Last Name] to Asc and i.e. 100-(Asc([Last
Name]) +100 if points = 0 and if not then (Asc([Last Name]) then sort
Ascending.

it works fine

Duane Hookom said:
Please respond with some sample records and the desired output.

--
Duane Hookom
MS Access MVP

Paul Dennis said:
Thanks for this, worked fine but didn't resolve my problem. I have a sort
order of [No of Rides] desc, [Last Name] Desc, however when the [No of
Rides]
= 0 I want the sort order to swap to [No of Rides] desc, [Last Name] Asc.

Can it be done?

Duane Hookom said:
It would take less time to try it this than to post the question in a
news
group.

Open Northwind and create a query with this SQL
SELECT Employees.*
FROM Employees
ORDER BY IIf([LastName] Like "D*",[LastName],"A");

--
Duane Hookom
MS Access MVP

Can you use an IIF statement in an ORDER BY statement in SQL?

Trying to change the order depending on the if statement?
 
Back
Top