0

I know I'm close to figuring this out but need a little help. What I'm trying to do is all grab a column from a particular table, but chop off the first 4 characters. For example if in a column the value is "KPIT08L", the result I was is 08L. Here is what I have so far but not getting the desired results.

 SELECT LEFT(FIELD_NAME, 4)
 FROM TABLE_NAME

5 Answers 5

2

First up, left will give you the leftmost characters. If you want the characters starting at a specific location, you need to look into mid:

select mid (field_name,5) ...

Secondly, if you value performance,portability and scalability at all, this sort of "sub-column" manipulation should generally be avoided. It's usually far easier (and faster) to patch columns together than to split them apart.

In other words, keep the first four characters in their own column and the rest in a separate column, and do your selects on the relevant one. If you're using anything less than a full column, then it's technically not one attribute of the row.

Sign up to request clarification or add additional context in comments.

Comments

1

Try with

SELECT MID(FIELD_NAME, 5)  FROM TABLE_NAME 

Mid is very powerfull, it let you select the starting point and all the remainder, or,
if specified, the length desidered as in

SELECT MID(FIELD_NAME, 5, 2)  FROM TABLE_NAME  ' gives 08 in your example text

Comments

0
SELECT RIGHT(FIELD_NAME,LEN(FIELD_NAME)-4)
 FROM TABLE_NAME;

If it is for a generic string then the above one will work...

1 Comment

This of course assumes the strings will have 7 characters, which might not always be the case.
0

Don't have Access at my current location, but please try this.

SELECT RIGHT(FIELD_NAME, LEN(FIELD_NAME)-4)
FROM TABLE_NAME

1 Comment

Seems a roundabout way to use mid() :-)
0

The LEFT(FIELD_NAME, 4) will return the first 4 caracters of FIELD_NAME.

What you need to do is :

 SELECT MID(FIELD_NAME, 5)
 FROM TABLE_NAME

If you have a FIELD_NAME of 10 caracters, the function will return the 6 last caracters (chopping the first 4)!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.