473,387 Members | 1,890 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,387 software developers and data experts.

Capturing data inside double quotes text

benchpolo
142 100+
I have a series of data rows where I need to capture the text inside the double quotes, but due to the different text length, I'm not quite sure how to do it.

Data:
"INSUFFICIENT INFORMATION" Not enough medical information
"NO MEDICAL NECESSITY" Based on the clinical information submitted
"INSUFFICIENT INFORMATION" Not enough medical information was submitted
"NOT A COVERED BENEFIT" The above noted service is not a benefit covered under
"OUT-OF-NETWORK TO IN-NETWORK" The request for Consultation

Please advise. Thanks.
Dec 3 '07 #1
2 3559
Jim Doherty
897 Expert 512MB
I have a series of data rows where I need to capture the text inside the double quotes, but due to the different text length, I'm not quite sure how to do it.

Data:
"INSUFFICIENT INFORMATION" Not enough medical information
"NO MEDICAL NECESSITY" Based on the clinical information submitted
"INSUFFICIENT INFORMATION" Not enough medical information was submitted
"NOT A COVERED BENEFIT" The above noted service is not a benefit covered under
"OUT-OF-NETWORK TO IN-NETWORK" The request for Consultation

Please advise. Thanks.
Looking at the data as is, the logic would be to capture the position in each of the strings of the last speechmark and cut from the data all text to the left of it leaving you with the data in speechmarks. The next step would then be to simply replace the speechmarks leaving you with the data.

Below is a user defined function that captures the numerical position of the last character defined as the parameter for @char when examining the parameter @string that is passed to it. Using the LEFT function then in any view, the logic is to return the characters upto the position of the last speechmark and then wrap the lot in a REPLACE function to remove the speechmarks fore and aft. We thus end up with a column of data called 'My Stripped Data' holding the values you require

Your method of calling the function to achieve this is based around the assumption that you have a table called TABLE1 and that there is a field called simply 'Mydata' and that in that Mydata field has many rows of the data you have outlined

Your SQL syntax for the view would be this

Expand|Select|Wrap|Line Numbers
  1. SELECT Mydata, REPLACE(LEFT(Mydata, dbo.GetLastChar(Mydata, '"')), '"', '') AS [My Stripped Data]
  2. FROM dbo.TABLE1
The above SQL will return two columns of data namely your original data and a column to the right of it containing the data you require.

The below is the user defined function

Expand|Select|Wrap|Line Numbers
  1.  
  2. Create function dbo.UDF_GetLastChar(@string varchar(8000), @char char)
  3. Returns INT
  4. As
  5. Begin
  6.         If isnull(@string, '') = '' OR isnull(@char, '') = ''
  7.         Return 0 
  8. declare @charpos int
  9. select @charpos = len(@string) - charindex(@char, reverse(@string)) + 1
  10. If @charpos > len(@string) 
  11. Select @charpos = 0
  12. Return @charpos
  13. end
  14.  
Regards

Jim :)
Dec 4 '07 #2
benchpolo
142 100+
Jim, thanks that works..
Dec 4 '07 #3

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

Similar topics

11
by: Jakanapes | last post by:
Hi all, I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes ('). I'm using PHP to pull text out of a mySQL table and then feed the text into...
7
by: Jack | last post by:
Hi, I am trying to test a sql statement in Access which gives me the error as stated in the heading. The sql statement is built as a part of asp login verification, where the userid and password...
9
by: Tom Weston | last post by:
Help I have 4 databases containing different data relating to safety, not written by me. It is not possible to merge the databases into one large data base. I would like to create a user interface...
4
by: (PeteCresswell) | last post by:
Is his just a flat-out "No-No" or is there some workaround when it comes time for SQL searches and DAO.FindFirsts against fields containing same? I can see maybe wrapping the value searched for...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
3
by: Alex Maghen | last post by:
I'm having trouble with my repeater: I'm binding my Repeater control to an OleDbDataReader object. My ASPX looks like this: <asp:Repeater ID="Rptr" runat="server"> <ItemTemplate> <asp:Label...
1
by: Marc Miller | last post by:
Hello everyone, First I'll address this as a textfile manipulation question and if there is no answer there, then I'll need to ask it as a vb ADO question. I have a text file that I'm reading...
4
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or...
16
by: Akhenaten | last post by:
I must be missing something rather obvious. I have the following snippet of code that echo's my result twice when it should be echoing just once (only one element in the array). What am I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.