Ltrim variable characters from string

Hi,

I need to Ltrim a group of characters from a string using as my selection, characters stored in a variable. I am doing this for multiple records in a recordset and storing the result to a field in a table.

The fields: ID (can vary in length), LinkCodeFM and FMCode

Example:

ID=11
LinkCodeFM=11-1C2

I want to save just "1C2" into a new field called FMCode, I have stored the ID into a variable mID as this changes from record to record. So I want to Ltrim what is contained in the variable "ID" & "-" from LinkCodeFM and store the result in FMCode. The catch is the ID can be 1, 2 or 3 characters long, so a simple Ltrim won't work. Can you use variable contents to a Ltrim a string? I look forward to your help...
mitch87Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sigmaconCommented:
update YOUTR_TABLE_NAME_HERE
set FMCode = (
          case when charindex('-', LinkCodeFM) > 0
                then right(LinkCodeFM, len(LinkCodeFM) - charindex('-', LinkCodeFM) - 1)
                else null
          end
      )

Explanation: This updates the FMCode column for ALL rows in the table. If the LinkCodeFM has a dash (checked by charindex('-', LinkCodeFM) > 0) then it sets it to remaining string after the dash, otherwise to NULL
)
0
sigmaconCommented:
SORRY - PLEASE IGNORE MY POST - ITS FOR SQL SERVER - I AM SOOO SILLY!
0
shanesuebsahakarnCommented:
UPDATE MyTable SET FMCode=Mid$([LinkCodeFM],Len([ID])+1)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mitch87Author Commented:
Thanks Shane...I used your code, and needed to tweak the last portion. The FMCode was including the dash, ex: -1C2. So I changed the location where the string begins to Len[ID]+2. This eliminated the dash from the string. Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.