473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

MS SQL to remove text from a string

ACCESS sql question: I have different length data in a field and I want to remove all the data in the string that is to the right of the '-' a dash. I can find the len of the string and I can find the position of the '-', but cannot seem to complete the syntax for the complete use

ex: 32A23-001 or 24A-002 or 312-01
I want to retreive the data before the dash only.
May 16 '13 #1
5 3099
Seth Schrock
2,965 Expert 2GB
If you are wanting the text that is to the right of the first '-', then you would use the Mid() function and set the starting point as the position of the '-' using the InStr() function. You might have to play with +/- 1 to get the exact starting location, but that is simple to play with.
May 16 '13 #2
Seth, my example really is showing I want the chars to the left of the dash, not to the right and I am not getting the syntax with using mid/instr/len tying them all together.
May 16 '13 #3
Here is what my ms access sql looks like right now and I am not getting the chars to the left of the dash:
mid([LED data from RDR-rev2].LGEY_ISGT_STALN_CD,InStr([LED data from RDR-rev2].[LGEY_ISGT_STALN_CD],"-"),len([LED data from RDR-rev2].LGEY_ISGT_STALN_CD) - instr([LED data from RDR-rev2].[LGEY_ISGT_STALN_CD],"-")) as Left_DashPos
May 16 '13 #4
Seth,
With trial and error I finally got it using left/instr below, so thank you for reply so quickly!:
left([LED data from RDR-rev2].LGEY_ISGT_STALN_CD,InStr([LED data from RDR-rev2].[LGEY_ISGT_STALN_CD],"-")-1) as Left_DashPos
May 16 '13 #5
Seth Schrock
2,965 Expert 2GB
Sorry, after re-reading your OP, I'm not sure why I thought it said "remove text to the LEFT" when it clearly says right. My bad. Glad you found the solution anyway.
May 16 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: grghoward | last post by:
I am receiving a series of Microsoft Word documents from web clients that they upload to my server. I need to convert them to XML to pass through to another system. I have done this through...
6
by: Jerry Werner | last post by:
I need to replace my email address on hundreds of web pages with a new address (in a graphic, not a mailto) in order to thwart the email harvesters that spammers are using. Ideally, I'd like to do...
3
by: soni29 | last post by:
hi, how can i remove a string from an existing string in javascript. i have a textbox in a form and want to make sure that when the user clicks a button that certain words are moved, like all...
2
by: charlie_M | last post by:
I have the following code: <script type=text/javascript> function hide_tooltip(){ var hp = document.getElementById("tooltipper"); hp.style.left=0; hp.style.top=0; hp.style.width=1;...
4
by: Brian Henry | last post by:
Say I have a text string like "0002323235-3434-3545" and I want to remove the leading zeros, would a regular expression work here? sorry I haven't worked with regex's that much and still need to...
5
by: geotso | last post by:
Here is the scenario: 1. I have a table (tblCalendar) with the following fields: caldID caldDate caldTitle caldInfo nWinW nWinH
2
by: Harry Haller | last post by:
Can I remove text from a StringWriter ? I have a StringWriter object, the content of which looks like this: "<div>Some other html which I wish to keep</div>" Can I remove the unwanted <div>,...
10
by: teenIce | last post by:
Hi all, Does anyone have suggestion what can I do to remove some string from a string? Like this : Original : I have a cat. Remove : have Result : I a cat. Thanks in advance.
4
by: Ahmed, Shakir | last post by:
I need to remove text string from the list of the numbers mentioned below: 080829-7_A 070529-5_c 080824-7_O 070405_6_p The output will be : 080829-7 070529-5
0
by: Adam Pletcher | last post by:
You just want to drop the last two characters? Slice it. 080829-7 - Adam Behalf
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.