By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,066 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,066 IT Pros & Developers. It's quick & easy.

How to search a string

100+
P: 134
How do I search a string -
I have a ms access table consist of 2 columns -

"Part Nos"..........."Components"
K123456............. U123,Q545,U5,Q3321,U22
P456789..............U13,U18,Q123,P555,X222

User enter a component number such as U5 and I must be able to retrieve
the Part Nos -K123456. How do I search thru the string in the "Components" column which is separate by comma.
May 22 '08 #1
Share this Question
Share on Google+
5 Replies


debasisdas
Expert 5K+
P: 8,127
You have to use LIKE search in database.
May 23 '08 #2

Expert 100+
P: 487
You can not split and search instead you can use Like %string%
(i.e)
Expand|Select|Wrap|Line Numbers
  1. Select * from tblTableName where SearchField like %searchString%
May 23 '08 #3

100+
P: 134
You can not split and search instead you can use Like %string%
(i.e)
Expand|Select|Wrap|Line Numbers
  1. Select * from tblTableName where SearchField like %searchString%
thanks you so much for the code
May 24 '08 #4

devonknows
100+
P: 137
Just thought i would offer a few modifications here if not for you then for others that would like to know.

Im assuming searchString is a variable (Which it would be if you was entering the search string into a textbox of some sorts), if so then the sql statement is not valid, beacuse it will just search the table for the word 'searchstring'.

This is the Old One.
Expand|Select|Wrap|Line Numbers
  1.  Sql = "Select * from tblTableName where SearchField like %searchString%"
This is What it Should be.
Expand|Select|Wrap|Line Numbers
  1.  Sql = "Select * from tblTableName where SearchField like '%" & SearchString & "%'"
Also, If your SearchString is more than one word like a two word phrase or something and you want to search for all instances of these words instead of the phrase as a whole then try something like this.

Expand|Select|Wrap|Line Numbers
  1.  Sql = "Select * from tblTableName where SearchField like '%" & Replace(SearchString, chr(32), chr(37)) & "%'"
What this does, it is replaces spaces (Chr(32)) with percentages (Chr(37)). if there is a percentage in the phrase it will be queried as a wildcard and will return all instances before the % and after the % or between multiple %.

Hope this is a little more insight
Kind Regards
Devon.
May 29 '08 #5

Expert 100+
P: 487
Most welcome for your valuable reply.
May 29 '08 #6

Post your reply

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