Solved

MS-ACCESS Select substring

Posted on 2003-11-03
3
5,457 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
3 Comments
 
LVL 9

Accepted Solution

by:
rherguth earned 150 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 50 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now