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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Global search - finding string in all fields

Author  Topic 

Marioi
Posting Yak Master

132 Posts

Posted - 2007-05-15 : 11:51:04
I am looking for a way to select or COUNT(*) rows in which any of the fields contain a string. Something like:

SELECT *
FROM t
WHERE * LIKE '%string%'

I can compose a dynamic statement in .net with tens of WHERE conditions with ORs, but is there a native TSQL way? I would restrict my dynamic statement to (n)char, (n)varchar and (n)text fields.

What is the best way to search through all tables? Loop through a cursor of tables returned by sysobjects?

TIA.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-15 : 11:55:46
See this: [url]http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm[/url]

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

Marioi
Posting Yak Master

132 Posts

Posted - 2007-05-15 : 14:43:23
Thank you, a nice sproc - saved me time!
Go to Top of Page
   

- Advertisement -