473,402 Members | 2,064 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,402 software developers and data experts.

How to extract part of a string

Is there a function that will extract part of a string when the data you
want does not occur in a specific position?
Field "REF" is varchar(80) and contains an email subject line and the email
recipients contact name
Example data:
Rec_ID REF
1 Here is the information you requested (oc:Johm
Smith)
2 Thanks for attending our seminar (oc:Peggy Sue
Johnson)
3 Re: Our meeting yesterday (oc:Donald A. Duck)

What I need to extract is the contact name that is in parenthesis after the
oc:
The name is always in parenthesis and occurs immediately after "oc:" - no
spaces after the "oc:"

Thanks.


Jul 23 '05 #1
4 30178
You could use PATINDEX or CHARINDEX along with a SUBSTRING in the
select statement to get what you are looking for. PATINDEX or CHARINDEX
will return the starting position of a particular string, you can use
it with SUBSTRING to extract the string that follows the oc:

Let me know if you need the actual SQL Statement to do what you are
looking for.

Jul 23 '05 #2
Thanks but I can't seem to get the syntax correct to extract this. Do you
have a sample SQL statement to do this?
"SQL_developer" <vl******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
You could use PATINDEX or CHARINDEX along with a SUBSTRING in the
select statement to get what you are looking for. PATINDEX or CHARINDEX
will return the starting position of a particular string, you can use
it with SUBSTRING to extract the string that follows the oc:

Let me know if you need the actual SQL Statement to do what you are
looking for.

Jul 23 '05 #3
SELECT SUBSTRING([Ref], CHARINDEX('(oc:', [Ref]) + 4, LEN([Ref]) -
(CHARINDEX('(oc:', [Ref]) + 4) - 1)
GeoSynch
"rdraider" <rd******@sbcglobal.net> wrote in message
news:wz****************@newssvr21.news.prodigy.com ...
Thanks but I can't seem to get the syntax correct to extract this. Do you
have a sample SQL statement to do this?
"SQL_developer" <vl******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
You could use PATINDEX or CHARINDEX along with a SUBSTRING in the
select statement to get what you are looking for. PATINDEX or CHARINDEX
will return the starting position of a particular string, you can use
it with SUBSTRING to extract the string that follows the oc:

Let me know if you need the actual SQL Statement to do what you are
looking for.


Jul 23 '05 #4
I started getting the error: "Invalid length parameter passed to the
substring function." and it cut off the last letter of the contact name so I
removed the -1 from the end of the query. Then I added the WHERE to just
give me the recordS with contact names (I found some records that just seem
to be garbage).
This query works well:
SELECT SUBSTRING([Ref], CHARINDEX('(oc:', [Ref]) + 4, LEN([Ref]) -
(CHARINDEX('(oc:', [Ref]) + 4))
FROM TABLENAME
WHERE REF LIKE '%(oc:%'
Thanks for your help, you saved me a lot of time.

"GeoSynch" <Sp********@Casablanca.com> wrote in message
news:Up*****************@newsread2.news.pas.earthl ink.net...
SELECT SUBSTRING([Ref], CHARINDEX('(oc:', [Ref]) + 4, LEN([Ref]) -
(CHARINDEX('(oc:', [Ref]) + 4) - 1)
GeoSynch
"rdraider" <rd******@sbcglobal.net> wrote in message
news:wz****************@newssvr21.news.prodigy.com ...
Thanks but I can't seem to get the syntax correct to extract this. Do
you have a sample SQL statement to do this?
"SQL_developer" <vl******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
You could use PATINDEX or CHARINDEX along with a SUBSTRING in the
select statement to get what you are looking for. PATINDEX or CHARINDEX
will return the starting position of a particular string, you can use
it with SUBSTRING to extract the string that follows the oc:

Let me know if you need the actual SQL Statement to do what you are
looking for.



Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lauren Quantrell | last post by:
Is there anyway to extract part of a string in a stored procedure using a parameter as the starting point? For example, my string might read: x234y01zx567y07zx541y04z My Parameter is an nvarchar...
3
by: Lauren Quantrell | last post by:
This a a long convoluted string parsing question... I have a string in an Access 2K database table field that I use for noting if a user has checked a record. The string goes like this: xy So...
1
by: | last post by:
Hiya, I need to extract a string (ascii) from a buffer, my buffer is dim buf(1023) as byte This buffer containg an "array" of type xxx type xxx is defined in C as follows
2
by: Eagle | last post by:
I have a record with, for instance 000-11-222-33 as text. Is there a way to extract just the 222 part? With the sidenote that the 222 part kan have 3 or 4 characters. The 000 and 11 part are...
1
by: nkg1234567 | last post by:
I'm trying to extract HTML from a website in the form of a string, and then I want to extract particular elements from the string using the substr function: here is some sample code that I have thus...
34
by: Umesh | last post by:
I want to extract a string abc*xyz from a text file. * indicates arbitrary no. of characters. I'm only able to do it when the string has definite no. of characters or the string length is...
0
by: Sriram Rajan | last post by:
I am wondering if I can use re.search to extract from a particular location in a string. Example: string1='/Users/sriram/folder1/folder2/folder3/folder4/folder5/file' re.search ('folder3,string1)...
18
by: Ecka | last post by:
Hi everyone, I'm trying to write a PHP script that connects to a bank's currency convertor page using cURL and that part works fine. The issue is that I end up with a page that includes a lot...
2
by: jmartmem | last post by:
Is there a function, or a combination of functions, in MS Access 2007 that will allow me to extract part of a string? I have a database text field "Email" that contains a person's name and email...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.