473,799 Members | 3,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 30203
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_develo per" <vl******@gmail .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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******@sbcgl obal.net> wrote in message
news:wz******** ********@newssv r21.news.prodig y.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_develo per" <vl******@gmail .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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********@Cas ablanca.com> wrote in message
news:Up******** *********@newsr ead2.news.pas.e arthlink.net...
SELECT SUBSTRING([Ref], CHARINDEX('(oc: ', [Ref]) + 4, LEN([Ref]) -
(CHARINDEX('(oc :', [Ref]) + 4) - 1)
GeoSynch
"rdraider" <rd******@sbcgl obal.net> wrote in message
news:wz******** ********@newssv r21.news.prodig y.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_develo per" <vl******@gmail .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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
9538
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 and the value is: "x567y" What I want to extract is the two charachters after the parameter, in this case "07". Can anyone shed some light on this problem? Thanks, lq
3
1780
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 the field looks like this: x123yx456yx543y and so on... I run a LIKE query when the form loads to determine the state of control CheckBox indicating if the user has checked the record:
1
1761
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
1593
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 always 3 and 2 characters each. Thanks!
1
3666
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 far: use HTTP::Request::Common; use LWP::UserAgent; use LWP::Simple; $ua = LWP::UserAgent->new;
34
2751
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 constant: i.e. five or the string is abc????? xyz How can i generalize it for any length of the string?
0
1010
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) <Extract /folder3/folder4/folder5/file> Thanks,
18
3975
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 of information that I don't need. Using the PHP function strip_tags I've ended with the text below and from the remaining HTML code, I'd like to extract the lines starting with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLEtag. How do...
2
7456
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 address enclosed in brackets. Not all field values have a name, but each has an email address contained by brackets. Here are 3 example field values: John Smith <johnsmith@email.com> <marysmith@email.com> Willard Smith <willardjsmith@email.com> ...
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.