?
Solved

MS-ACCESS Select substring

Posted on 2003-11-03
3
Medium Priority
?
5,494 Views
Last Modified: 2012-05-04
Hello EVeryone,

I'm working on a a critical report and I was forced to used MS-ACCESS over ORACLE.  Now I'm stuck with a basic select statement.  Anyway, to make a long story short, I want to select the first two digits of a column in access -- how can I do this.  For eg, the column always contains a 4 character field like 4443 (this is not a number).  All I want to do is select the first two characters, in this case '44'.  Any ideas?    Please this is an urgent call -- I've attached 200 points to this question.  Thanks for your time and help!!

ITorBust
0
Comment
Question by:itorbust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
rherguth earned 600 total points
ID: 9673826
The expression you're looking for is LEFT()

An example:
SELECT Left(FirstName, 2) as left2 FROM Contacts;

To do this through the interface, you could just click new query in Access and then select SQL View from the View menu and type in your SQL.   If you then switch back to design view, you'll see how to set the expression with the GUI.  I suspect you're more comfortable just typing the SQL anyway.

-- Bob
0
 
LVL 15

Assisted Solution

by:namasi_navaretnam
namasi_navaretnam earned 200 total points
ID: 9675569
Access equalent of substring is MID or MID$ function.

Select Mid$('Namasi, 2, 2)  //returns "am"
0
 

Expert Comment

by:arnaudduplessy
ID: 9680000
This is for first two characters from the left:

SELECT FieldName
FROM TableName
WHERE Left([FieldName],2)="Criteria";
---------------------------------------------------
This is for mid three characters starting a the second character from the left:
SELECT FieldName
FROM TableName
WHERE  Mid([FieldName],2,3)="Criteria";
----------------------------------------------------
This is for first two characters from the right:
SELECT FieldName
FROM TableName
WHERE Right([FieldName],2)="Criteria";

0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question