T
Tomk
is there a way to sort the list of names of organizations in a table and
ignore the word "the" preceeding a name?
ignore the word "the" preceeding a name?
Ken said:Firstly, never sort a table per se, always use a query to sort records. The
exception is if the query is used as a RecordSource for a report, in which
case use an unsorted query and use the query's internal sorting and grouping
mecahnism to oreder the records.
As regards your question you can use the Replace function to return a value
which excludes the "the " (note the trailing space, its important). So in a
query you'd order it with:
ORDER BY Replace([Orgabization], "the ","")
To do this in query design view, in the 'field' row of a blnak column enter:
SortColumn: Replace([Organization], "the ","")
In its 'sort' row select 'Ascending'.
If you are opening the query directly or using it as the basis for a form
you can uncheck the 'show' checkbox. If using it as the basis for a report
then leave it checked and sort the report internally on SortColumn using the
sorting and grouping dialogue in report design view. You don't need to show
the SortColumn in the report of course.
The reason for the trailing space BTW is that 'the' might be a substring of
an organization name e.g. 'The theatre company'; you don't want this to be
returned as 'atre company' which is what would happen without the trailing
space. You might have 'the ' as a word within a name or as a substring at
the end of a word of course, which would be replaced for sorting purposes
with a zero length string, but that's probably not going to make any
significant difference to the resulting sort order.
Incidentally the Replace function doesn't actually remove any data from the
table, it simply returns a value with the string in question replaced by
another string. To permanently remove it you'd have to call it in an UPDATE
query, not a normal SELECT query.
Ken Sheridan
Stafford, England
Tomk said:is there a way to sort the list of names of organizations in a table and
ignore the word "the" preceeding a name?
SELECT Mid(TableName!FieldName,InStr(TableName!FieldName," ")+1) AS SortedNames
FROM TableName
ORDER BY Mid(TableName!FieldName,InStr(TableName!FieldName," ")+1);
But the 1st word is "The" which they don't want - I think / hope![]()
?ignore the word "the" preceeding a name?is there a way to sort the list of names of organizations in a
table and
Ken Sheridan said:Firstly, never sort a table per se, always use a query to sort records. The
exception is if the query is used as a RecordSource for a report, in which
case use an unsorted query and use the query's internal sorting and grouping
mecahnism to oreder the records.
As regards your question you can use the Replace function to return a value
which excludes the "the " (note the trailing space, its important). So in a
query you'd order it with:
ORDER BY Replace([Orgabization], "the ","")
To do this in query design view, in the 'field' row of a blnak column enter:
SortColumn: Replace([Organization], "the ","")
In its 'sort' row select 'Ascending'.
If you are opening the query directly or using it as the basis for a form
you can uncheck the 'show' checkbox. If using it as the basis for a report
then leave it checked and sort the report internally on SortColumn using the
sorting and grouping dialogue in report design view. You don't need to show
the SortColumn in the report of course.
The reason for the trailing space BTW is that 'the' might be a substring of
an organization name e.g. 'The theatre company'; you don't want this to be
returned as 'atre company' which is what would happen without the trailing
space. You might have 'the ' as a word within a name or as a substring at
the end of a word of course, which would be replaced for sorting purposes
with a zero length string, but that's probably not going to make any
significant difference to the resulting sort order.
Incidentally the Replace function doesn't actually remove any data from the
table, it simply returns a value with the string in question replaced by
another string. To permanently remove it you'd have to call it in an UPDATE
query, not a normal SELECT query.
Ken Sheridan
Stafford, England
Tomk said:is there a way to sort the list of names of organizations in a table and
ignore the word "the" preceeding a name?
John Spencer said:Ken, you could change the replace to only replace the first occurence of
"The ", but you still could have un-intended replacements.
Replace([Organization],"The ","",1,1)
replaces only the first incidence of "The " in the name
"Wythe Corporation" would become "WYCorporation"
Safer would be to sort by
IIF([Organization] Like "The *",Mid([Organization],5),[Organization])
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
Ken said:Firstly, never sort a table per se, always use a query to sort records. The
exception is if the query is used as a RecordSource for a report, in which
case use an unsorted query and use the query's internal sorting and grouping
mecahnism to oreder the records.
As regards your question you can use the Replace function to return a value
which excludes the "the " (note the trailing space, its important). So in a
query you'd order it with:
ORDER BY Replace([Orgabization], "the ","")
To do this in query design view, in the 'field' row of a blnak column enter:
SortColumn: Replace([Organization], "the ","")
In its 'sort' row select 'Ascending'.
If you are opening the query directly or using it as the basis for a form
you can uncheck the 'show' checkbox. If using it as the basis for a report
then leave it checked and sort the report internally on SortColumn using the
sorting and grouping dialogue in report design view. You don't need to show
the SortColumn in the report of course.
The reason for the trailing space BTW is that 'the' might be a substring of
an organization name e.g. 'The theatre company'; you don't want this to be
returned as 'atre company' which is what would happen without the trailing
space. You might have 'the ' as a word within a name or as a substring at
the end of a word of course, which would be replaced for sorting purposes
with a zero length string, but that's probably not going to make any
significant difference to the resulting sort order.
Incidentally the Replace function doesn't actually remove any data from the
table, it simply returns a value with the string in question replaced by
another string. To permanently remove it you'd have to call it in an UPDATE
query, not a normal SELECT query.
Ken Sheridan
Stafford, England
Tomk said:is there a way to sort the list of names of organizations in a table and
ignore the word "the" preceeding a name?
I must have misunderstand
?ignore the word "the" preceeding a name?
Oh well![]()
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.