Order By in Expression (1 Viewer)

jack555

Member
Local time
Today, 09:41
Joined
Apr 20, 2020
Messages
93
how to sort a field populated by expression? Created a filed TextLength using LEN([fieldname]; now need to sort the TextLength column by ascending or descending. However it is working. Please help.
 

Minty

AWF VIP
Local time
Today, 06:41
Joined
Jul 26, 2013
Messages
10,368
The simple way is to save that query, and then create another one based on it.
Then you will be able to sort it, in the new query.
 

Ranman256

Well-known member
Local time
Today, 01:41
Joined
Apr 9, 2015
Messages
4,339
all expressions in a query have a name. you can name it in the query like:
MySortFld: LEN([fieldname]
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:41
Joined
Feb 19, 2002
Messages
43,233
If you don't know how to write SQL, the best way to learn is to do it with the QBE and then switch to SQL View. Many people object to using QBE because it has limitations they don't like. If you don't know how to write SQL, then don't be proud. Use the QBE. What you'll see is if you have an expression in your select clause that you want to sort on, you can add ascending or descending in the order by clause. When you switch to SQL view, you will see that the QBE copied your expression from the select clause and duplicated it in the Order by clause.

Or, in my case, I work with too many applications to keep hundreds of table names and thousands of column names in current memory so I always use the QBE to at least create my Select query. I am not proud. I am lazy and a lousy typist so for me, QBE eliminates all the early, typos. Then since I only use embedded SQL if it is actually dynamic, I just stick with the querydefs. Taking parameters does not make a query dynamic. What makes a query dynamic is modifying something structural like determining a where clause at run time as you might with a complex search form. Or needing an In() clause to use as criteria or a Top n. If n is variable, the query is dynamic and you need to create it with SQL.
 

Users who are viewing this thread

Top Bottom