Jump to content

ExecuteSQL() ORDER BY FIELD function


This topic is 1939 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi Gang,

I am reaching out to see if anyone can assist (or maybe point me in the right direction) with some ExecuteSQL() issues I am having in my my next version of my product.
 
I want to execute a query like the following:
 
SELECT code FROM Appts WHERE appt_id IN (’14’,’10’,’8’,’9') ORDER BY FIELD(appt_id, ‘9', ‘10', ‘8', ‘14’)
 
I have tried several times for this to return a working result with NO LUCK. Do you know if FMP allows this sort of query or does it fall short.
 
Appreciate any help. Thanks!
Link to comment
Share on other sites

Ah. I was reading something else that made me realize what this is about. 

There is no FIELD function in Filemaker SQL syntax. To sort the records by custom sort order, try:

SELECT code 
FROM Appts 
WHERE appt_id IN (’14’,’10’,’8’,’9') 
ORDER BY CASE appt_id 
   WHEN '9' THEN '1'
   WHEN '10' THEN '2'
   WHEN '8' THEN '3'
   ELSE '4' END 

 

Link to comment
Share on other sites

This topic is 1939 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.