Using SUBSTRING in query

  • Thread starter walter via AccessMonster.com
  • Start date
W

walter via AccessMonster.com

This is a query-of-query in ColdFusion and MSAccess

This works ok

<cfquery name="session.getAlpha" dbtype="query">
select distinct signerName
from session.getSigs
</cfquery>

Instead, I would like to select just the "first letter" of signerName in
alphabetical order:

<cfquery name="session.getAlpha" dbtype="query">
select distinct substring(signerName,1,1) as alpha
from session.getSigs
orderby alpha
</cfquery>

and it fails. This is giving me a rough time, im just not making the query
right ...
Any help much appreciated!
 
D

Duane Hookom

You are attempting to run a query of queries that has a more limited support
for SQL and functions. You might need to create the alpha column in your
sessions.getSigs. You could then group by the alpha in the query of queries.
 
J

John Vinson

Instead, I would like to select just the "first letter" of signerName in
alphabetical order:

<cfquery name="session.getAlpha" dbtype="query">
select distinct substring(signerName,1,1) as alpha
from session.getSigs
orderby alpha
</cfquery>

and it fails. This is giving me a rough time, im just not making the query
right ...
Any help much appreciated!

If Access is processing the query (I don't use ColdFusion so I'm not
sure how dbtype="query" will work), use the Access function Left()
instead of the ColdFusion function substring:

select distinct Left(signername. 1) as alpha

The substringing operation is handled in Access using the functions
Left(), Right(), and Mid(). See the VBA online help for syntax.

John W. Vinson[MVP]
 

Ask a Question

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.

Ask a Question

Top