Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT ... WHERE ... LIKE

Author  Topic 

ossama
Starting Member

2 Posts

Posted - 2007-12-24 : 08:22:45
hello, this is my first post here,
i have a table with many columns (i am using ms access) and i want to search for a word in all columns, how can i use SELECT WHERE LIKE against all the columns at once (not against each coloumn)

SELECT * FROM MyTable WHERE (all the columns in the table) LIKE '%What_I_Am_Searching%'

thank you in advance

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-24 : 08:36:02
You can try variation of technique shown in this article:
http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

ossama
Starting Member

2 Posts

Posted - 2007-12-24 : 08:47:13
i am new in sql, the script in that page is very complicate to me, i habituated myself in simple queries against a database (i am using queries using ODBC functions like SQLExecDirect)
Go to Top of Page

georgev
Posting Yak Master

122 Posts

Posted - 2007-12-25 : 18:14:00
Unfortunately there is no such thing as a LIKE IN comparison... however they do exist separately
[CODE]
DECLARE @searchStr char(6)
SET @searchStr = 'George'

SELECT *
FROM myTable
WHERE field1 LIKE '%' + @searchStr + '%'
OR field2 LIKE '%' + @searchStr + '%'
...
OR fieldN LIKE '%' + @searchStr + '%'

SELECT *
FROM myTable
WHERE @searchStr IN (field1, field2 ... fieldN)
[/CODE]


George
<3Engaged!
Go to Top of Page
   

- Advertisement -