Hi, I m usng Ms-Access 2007 with vb.net.
My problem is that I have a table with column name strval which has following values:
2,3,43,5,6 etc in each row.
Now I want to search for that row which contains e.g 2 in cloumn strval .
i use
SELECT *
FROM tbl where tbl.strval IN( '2' )
but this doesn't work.

Please help.
Thanks

Recommended Answers

All 3 Replies

Don't use the in clause.

Use SELECT * FROM tbl WHERE (tbl.strval='2')

You can later alter this to pass a variable where the 2 is to qiery dynamically

contains? as in "123", "12", "23" all contain 2

if that's what you want:
SELECT t.*
FROM tbl AS t
WHERE t.strval LIKE "*2*"

if LIKE "*2*" wont fly then experiment with variations of quote (' or ") and wildcard (* or %). e.g. LIKE '*2*', LIKE "%2%" etc

It's a table scan so wont be fast on a huge table.

@izyrider Thank you for that I forgot the wildcard while typing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.