Find a word in comments field

  • Thread starter Thread starter David
  • Start date Start date
D

David

I can create a query that finds a word in the "comments" field (200 char
text field).

I need the results to show the word searched for plus the next 7 characters
after the word.

How?
 
UNTESTED SQL Statement.

SELECT MID(Comments,Instr(1,Comments,"SomeWord"),Len("SomeWord")+7)
FROM Table
WHERE Instr(1,Comments,"SomeWord")>0

Optionally

SELECT MID(Comments,Instr(1,Comments,"SomeWord"),Len("SomeWord")+7)
FROM Table
WHERE Comments Like "*SomeWord*"
 
The first version works!

Thank you

John Spencer (MVP) said:
UNTESTED SQL Statement.

SELECT MID(Comments,Instr(1,Comments,"SomeWord"),Len("SomeWord")+7)
FROM Table
WHERE Instr(1,Comments,"SomeWord")>0

Optionally

SELECT MID(Comments,Instr(1,Comments,"SomeWord"),Len("SomeWord")+7)
FROM Table
WHERE Comments Like "*SomeWord*"
 
I faced a similar problem. I need to further replace this
word with another value.

I change the SQL statement to:

UPDATE Table SET MID(Comments,Instr
(1,Comments,"SomeWord"),Len("SomeWord")+7) = "NewValue"
WHERE Comments Like "*SomeWord*"

I was prompted as there was syntax error. How should I fix
this?
 
Back
Top