Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ltrim variable characters from string

Posted on 2004-10-23
4
Medium Priority
?
865 Views
Last Modified: 2010-05-18
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...
0
Comment
Question by:mitch87
[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
  • 2
4 Comments
 
LVL 8

Expert Comment

by:sigmacon
ID: 12391627
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
 
LVL 8

Expert Comment

by:sigmacon
ID: 12391631
SORRY - PLEASE IGNORE MY POST - ITS FOR SQL SERVER - I AM SOOO SILLY!
0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 375 total points
ID: 12391647
UPDATE MyTable SET FMCode=Mid$([LinkCodeFM],Len([ID])+1)
0
 

Author Comment

by:mitch87
ID: 12396115
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

610 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