473,387 Members | 1,606 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.

Query keywords within text field

114 100+
Hello all,

I'm thinking this is a simple question...

I have a table (tblData) that includes a large-capacity text field (255 characters). I would like to write a query that pulls records that have specific keywords within that text field (txtComments).

I've tried the following sql with no success:
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, Name, Comments
  2. FROM tblData
  3. WHERE Comments IN ("best","amazing","George")
  4. ORDER BY ID;
eg of a record that would be pulled:
ID
3

Name
John Smith

Comments
Best service ever.

Any ideas out there? Thank you!
martin
Nov 19 '07 #1
6 3513
Rabbit
12,516 Expert Mod 8TB
You're looking for the Like operator. However, if you want to use a variable amount of keywords, you're looking at VBA to rewrite the SQL each time you want to run it.
Nov 19 '07 #2
martin DH
114 100+
You're looking for the Like operator. However, if you want to use a variable amount of keywords, you're looking at VBA to rewrite the SQL each time you want to run it.
I see. The keywords will remain constant (although what they are I have yet to decide). I'm sorry but I'm having a little memory lapse on LIKE.

If I want to pull records that have either "best" and/or "conversion" somewhere in the Comments fields, is this the correct syntax?

Comments LIKE "[best, conversion]"
Nov 19 '07 #3
Rabbit
12,516 Expert Mod 8TB
You'll have to use Comments Like "*Best*" OR Comments Like "*Conversion*"
Nov 19 '07 #4
martin DH
114 100+
You'll have to use Comments Like "*Best*" OR Comments Like "*Conversion*"
Right. Thank you, Rabbit.
martin
Nov 20 '07 #5
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.
Nov 20 '07 #6
ADezii
8,834 Expert 8TB
Hello all,

I'm thinking this is a simple question...

I have a table (tblData) that includes a large-capacity text field (255 characters). I would like to write a query that pulls records that have specific keywords within that text field (txtComments).

I've tried the following sql with no success:
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, Name, Comments
  2. FROM tblData
  3. WHERE Comments IN ("best","amazing","George")
  4. ORDER BY ID;
eg of a record that would be pulled:
ID
3

Name
John Smith

Comments
Best service ever.

Any ideas out there? Thank you!
martin
I could not find the original code which I created, but I crudely reproduced it below. The original intent was to search Text/Memo Fields for a large number of Keywords which were entered into a Table (tblKeywords). This is accomplished by nested Recordset Loops one for the Keywords and one for matches on each Keyword. The results are then posted to a Table (tblResults). I'll post the code below, and if your are interested or need further information just let me know.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  2. Dim rstKeywords As DAO.Recordset, MySQL As String
  3. Dim rstResults As DAO.Recordset, strSQLSearch As String
  4. Dim rstSearchResults As DAO.Recordset
  5.  
  6. 'Clear the Results Table (tblResults)
  7. DoCmd.SetWarnings False
  8.   MySQL = "DELETE * From tblResults;"
  9.   DoCmd.RunSQL MySQL
  10. DoCmd.SetWarnings True
  11.  
  12. Set MyDB = CurrentDb()
  13.  
  14. Set rstKeywords = MyDB.OpenRecordset("tblKeywords", dbOpenForwardOnly)
  15. 'Will store the actual results
  16. Set rstResults = MyDB.OpenRecordset("tblResults", dbOpenTable)
  17.  
  18.  
  19. Do While Not rstKeywords.EOF    'Loop through all the Keywords, find matches below
  20.   strSQLSearch = "Select * From tblData Where [Comments] Like '*" & rstKeywords![Keyword] & "*'"
  21.   Set rstSearchResults = MyDB.OpenRecordset(strSQLSearch, dbOpenDynaset)
  22.     Do While Not rstSearchResults.EOF
  23.       With rstResults
  24.         .AddNew
  25.           ![ID] = rstSearchResults![ID]
  26.           ![Name] = rstSearchResults![Name]
  27.           ![Comments] = rstSearchResults![Comments]
  28.         .Update
  29.         rstSearchResults.MoveNext
  30.       End With
  31.     Loop
  32.       rstKeywords.MoveNext
  33. Loop
  34.  
  35. 'Clean up chores
  36. rstKeywords.Close
  37. rstResults.Close
  38. rstSearchResults.Close
  39. Set rstKeywords = Nothing
  40. Set rstResults = Nothing
  41. Set rstSearchResults = Nothing
  42.  
Nov 21 '07 #7

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

Similar topics

6
by: Mark Reed | last post by:
Hi all, Please help. I have a table with 2 fields of which I am trying to change a select query into a delete query. the select query is: SELECT Table1.Date, Min(Table1.Ball) AS MinOfBall...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
6
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 ...
5
by: mforema | last post by:
Hi Everyone, I want to search records by typing in multiple keywords. I currently have a search form. It has a combo box, text box, Search command button, and a subform. The combo box lists the...
23
by: mforema | last post by:
Hi everybody, I need to create a query that will search based on keywords and major categories. My tables are set-up as follows: tblLiteratureArticles: Abbreviation(FK) ArticleID(PK) Author...
4
by: Philip_collins | last post by:
Hi! I have a dynamic query that has a form attached. I want to add up a field with the sum funtion, the field is netkg. Dim rec As Recordset Dim qdf As QueryDef Dim strsql Set db =...
2
by: willyc | last post by:
Hello all, hopefully you will kind enough to offer some assistance.... I want to make what i believe could be quite a complex query, something beyond the 'basic' access queries. I'm not afraid of...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
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...
0
BarryA
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...
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...

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.