Folks
Not sure how to tackle this in DB2...
I'd like to have a query that would check for the presence of a given
token in a text string and return the next "word".
Let's have Table1 with text field Field1:
Field1
---------------------------------------
This is a test !
Color blue or red !
Katrina is a CAT4 hurricane !
I'd like to search for "Color" and return the string "blue"
(the word delimiter being one or more space...
Any idea / suggestion welcome
Regards
--alexT 4 1142
------------------------- Commands Entered -------------------------
CREATE TABLE NextWord
(Field1 VARCHAR(30)
);
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.
------------------------- Commands Entered -------------------------
INSERT INTO NextWord
VALUES
('This is a test')
,('Color blue or red')
,('Katrina is a CAT4 hurricane')
,('Color blue or red')
,('My Car Color is blue')
;
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.
------------------------- Commands Entered -------------------------
SELECT Field1_Org
, SUBSTR(Field1,1,exist*(POSSTR(Field1,' ')-1)) Next_word
FROM (SELECT Field1
, LTRIM(SUBSTR(Field1,POSSTR(' '||Field1,' Color ')+6)) ||
' '
, SIGN(POSSTR(' ' || Field1,' Color '))
FROM NextWord
) Q(Field1_Org,Field1,exist);
------------------------------------------------------------------------------
FIELD1_ORG NEXT_WORD
------------------------------ -------------------------------
This is a test
Color blue or red blue
Katrina is a CAT4 hurricane
Color blue or red blue
My Car Color is blue is
5 record(s) selected.
Minor revised example:
SELECT Field1
, SUBSTR(Field2,1,SIGN(POSSTR(' '||Field1,' Color '))
*(POSSTR(Field2,' ')-1)) Next_word
FROM (SELECT Field1
, LTRIM(SUBSTR(Field1,POSSTR(' '||Field1,' Color ')+6)) ||
' '
FROM NextWord
) Q(Field1,Field2);
DECLARE GLOBAL TEMPORARY TABLE SESSION.NextWord(Field1 VARCHAR(30))
INSERT INTO SESSION.NextWord (Field1) \
VALUES \
('This is a test'), \
('Color blue or red'), \
('Katrina is a CAT4 hurricane'), \
('Color blue or red'), \
('My Car Color is blue'), \
('Blue is a very nice Color ')
SELECT \
SUBSTR \
( \
LTRIM(SUBSTR(Field1, LOCATE('Color ', Field1) + 6)), \
1, \
LOCATE \
( \
' ', \
LTRIM(SUBSTR(Field1, LOCATE('Color ', Field1) + 6)) \
) - 1 \
) \
FROM \
SESSION.NextWord \
WHERE \
LOCATE('Color ', Field1) > 0 \
AND LOCATE \
( \
' ', \
LTRIM(SUBSTR(Field1, LOCATE('Color ', Field1) + 6)) \
) - 1 > 0
DROP TABLE SESSION.NextWord
Of course, it'd be a lot easier if it wasn't 1 *or more* spaces.
B.
Wow - thanks !
I've learn something :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jonathan |
last post by:
Hi all!
For a match schedule I would like to find all possible combinations of
teams playing home and away (without teams playing to themselves of course).
I now the simple version works...
|
by: cassandra.flowers |
last post by:
Hi,
I was wondering if it is possible (Using access) to have a query parameter
as a drop down box rather than a text box?
e.g. typing as criteria for a query produces a box with a
text box...
|
by: Michelle |
last post by:
I have took another approach to my database and have created a field
in my clients table with a 'client status' field, which is a combo
box/value list that is a pulldown menu of 3 choices (active...
|
by: Ryan Hubbard |
last post by:
I would like to run a query from VBA. The query will be one with
parameters. Is there a way to run the query and have Access prompt
for the values like it does if I where to execute it through...
|
by: Pea |
last post by:
Is it possible to get the average in a query where I have multiple
criteria?
Here's an abbreviated example of the query in design view:
Fields: USERID DATE TIME ID_TYPE...
|
by: d.p. |
last post by:
Hi all,
I'm using MS Access 2003.
Bare with me on this description....here's the situation: Imagine insurance,
and working out premiums for different insured properties. The rates for
calculating...
|
by: jjturon |
last post by:
Can anyone help me??
I am trying to pass a Select Query variable to a table using Dlookup
and return the value to same select query but to another field.
Ex.
SalesManID ...
|
by: jim Bob |
last post by:
Hi, I have a query with the criteria of
(!..) Or
!..
When I provide the value from qmylist, a second pop up appears waiting
for the value from lstResults. If I enter nothing and click ok, it...
|
by: forbes |
last post by:
Hi,
I have a user that used the Query Wizard to create a query in Access.
Now she claims that her master table is missing all the data that was
excluded from the query. Can you create anything...
|
by: jonm4102 |
last post by:
I'm trying to calculate the median of some numerical data. The data can
only be found in a query (henceforth query 1) field I previously made,
and I would prefer to calculate the median in a new...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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,...
|
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: 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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |