Solved

SQL Like operator

Posted on 2004-10-09
3
11,026 Views
Last Modified: 2011-08-18
I am searching to find like items, for instance Bath tub, Bath tub jetted, Bath tub white.

I use this sql to find like items:
sql = "SELECT DISTINCT ContractItems.txtItemDescription " & _
                     "FROM ContractItems " & _
                     "WHERE ContractItems.txtItemType  LIKE '" & msItemType & "%" & "'"

This works as long as the first word is bath.  If I type tub then 0 records found.  I want to be able to fine tub no matter where its located in the string even if it's"bathtub". What is the correct syntax to do that.  I've tried  ' "%" " & msItemType & "%" & "'" but that gives syntax error and I don't know if it will work with "baththb".

Thanks in advance
0
Comment
Question by:Moed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 125 total points
ID: 12267340
You've got the right idea, you just need your string variable to end up with:

WHERE ContractItems.txtItemType LIKE '%tub%'

So make sure msItemType doesn't have a single quote in it, and try this:

sql = "SELECT DISTINCT ContractItems.txtItemDescription " & _
                     "FROM ContractItems " & _
                     "WHERE ContractItems.txtItemType  LIKE '%" & msItemType & "%'"
0
 
LVL 2

Author Comment

by:Moed
ID: 12267421
Thats perfect.   Thanks a million.  I've only been programming for a few months and the proper placement of the ' and " and % and * drives me nuts.  
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12267460
Don't worry, when you've been at it longer, you'll find a lot more to drive you nuts.   ;)
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS troubles 4 82
physical_device_name field in SQL 3 36
Need help in debugging a UDF results 7 51
MS Access populate a field based on 2 other form fields 14 32
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question