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: - SELECT ID, Name, Comments
-
FROM tblData
-
WHERE Comments IN ("best","amazing","George")
-
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
6 3513
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.
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]"
You'll have to use Comments Like "*Best*" OR Comments Like "*Conversion*"
You'll have to use Comments Like "*Best*" OR Comments Like "*Conversion*"
Right. Thank you, Rabbit.
martin
Not a problem, good luck.
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: - SELECT ID, Name, Comments
-
FROM tblData
-
WHERE Comments IN ("best","amazing","George")
-
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. -
Dim MyDB As DAO.Database, MyRS As DAO.Recordset
-
Dim rstKeywords As DAO.Recordset, MySQL As String
-
Dim rstResults As DAO.Recordset, strSQLSearch As String
-
Dim rstSearchResults As DAO.Recordset
-
-
'Clear the Results Table (tblResults)
-
DoCmd.SetWarnings False
-
MySQL = "DELETE * From tblResults;"
-
DoCmd.RunSQL MySQL
-
DoCmd.SetWarnings True
-
-
Set MyDB = CurrentDb()
-
-
Set rstKeywords = MyDB.OpenRecordset("tblKeywords", dbOpenForwardOnly)
-
'Will store the actual results
-
Set rstResults = MyDB.OpenRecordset("tblResults", dbOpenTable)
-
-
-
Do While Not rstKeywords.EOF 'Loop through all the Keywords, find matches below
-
strSQLSearch = "Select * From tblData Where [Comments] Like '*" & rstKeywords![Keyword] & "*'"
-
Set rstSearchResults = MyDB.OpenRecordset(strSQLSearch, dbOpenDynaset)
-
Do While Not rstSearchResults.EOF
-
With rstResults
-
.AddNew
-
![ID] = rstSearchResults![ID]
-
![Name] = rstSearchResults![Name]
-
![Comments] = rstSearchResults![Comments]
-
.Update
-
rstSearchResults.MoveNext
-
End With
-
Loop
-
rstKeywords.MoveNext
-
Loop
-
-
'Clean up chores
-
rstKeywords.Close
-
rstResults.Close
-
rstSearchResults.Close
-
Set rstKeywords = Nothing
-
Set rstResults = Nothing
-
Set rstSearchResults = Nothing
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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: 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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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: 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...
| |