﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Kenneth Fisher  / Find a text string in any column in a database. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 02:53:00 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>Thank you. Very useful and simple.</description><pubDate>Fri, 22 Feb 2013 02:57:37 GMT</pubDate><dc:creator>SQL Surfer '66</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>If you are using "results to text" the output will be between the 3rd and 4th "(1 row(s) affected)" .I'm adding a SET NOCOUNT ON to the top of the script in order to turn off the extra output.  You probably arn't getting any results.  If you switch to "results to grid" you will get your results seperate from the text output.Kenneth</description><pubDate>Fri, 18 May 2012 14:27:53 GMT</pubDate><dc:creator>Kenneth.Fisher</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>How do you see the results?.  When I execute the script I get a bunch of '(1 row(s) affected'.  Thanks for your assistance.</description><pubDate>Fri, 18 May 2012 09:45:51 GMT</pubDate><dc:creator>punkcoi</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>Actually I'll bet you have your default collation set to be case sensative.  On all of the systems I have run it on the server has been case in-sesative so I didn't have any problems.Hope you find the script helpful :)Kenneth</description><pubDate>Tue, 12 Feb 2008 09:25:54 GMT</pubDate><dc:creator>Kenneth.Fisher</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>Actually the answer was quite simple: quite why I am not sure, but on our system all these objects are defined with upper case names and have to be referenced as such, e.g. "INNER JOIN INFORMATION_SCHEMA.TABLES Tables ON Columns.TABLE_NAME = Tables.TABLE_NAME". Many Thanks.</description><pubDate>Tue, 12 Feb 2008 09:20:38 GMT</pubDate><dc:creator>Philip Davis</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>They are system views.  They do only exist in Master but everyone should have access to them and they can be used from any database.  Just like the system stored procedures.  I'm honestly not sure why you can't use them normally.  If you want I can re-write it to work on the base system tables.</description><pubDate>Tue, 12 Feb 2008 08:04:50 GMT</pubDate><dc:creator>Kenneth.Fisher</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>I admit my SQL knowledge is extremely limited, but am I missing something very basic here? All I get is an Error 208 - Invalid Object Name INFORMATION_SCHEMA.Tables. It would appear that these views only exist in and relate to the master database on our system. All of our other databases, setup by applications such as a Sage ERP system, Backup Exec, etc., have no such views.</description><pubDate>Tue, 12 Feb 2008 04:48:11 GMT</pubDate><dc:creator>Philip Davis</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>[quote][b]toniupstny (2/8/2008)[/b][hr]Nice script.  A couple of questions for you:   - Shouldn't there be a set of [ ] around the variables in case they contain special characters like blanks or SQL keywords?   - How can you handle special characters in the LIKE comparison if a string you would search for has a %, _, [ ], [^ ] or quotes? Toni[/quote]I've now added the []'s around the table_name and column_name.  I'm not sure when the update will be posted but its a fairly simple change.Change this line [code]		' FROM ' + @Table_Name + ' (NOLOCK) WHERE ' + @Column_Name + ' LIKE ''%' + @Search_For + '%'''[/code]To this line[code]		' FROM [' + @Table_Name + '] (NOLOCK) WHERE [' + @Column_Name + '] LIKE ''%' + @Search_For + '%'''[/code]As far as pattern searching goes if you want to search on a pattern matching character put it in []'s.  So for example if you want to search for the literal string 'test%' you would put it as 'test[%]'.I thought about putting it in code but then you couldn't add extra patterns.  For example as it stands you can search on the word 'test' with a single digit number after it by making the search string 'test[0-9]'Kenneth</description><pubDate>Fri, 08 Feb 2008 07:37:52 GMT</pubDate><dc:creator>Kenneth.Fisher</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>Fair point.  I'll have to make the change.  The times that I used it I wasn't looking for anything with special characters or keywords.</description><pubDate>Fri, 08 Feb 2008 07:13:29 GMT</pubDate><dc:creator>Kenneth.Fisher</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>[quote][b]toniupstny (2/8/2008)[/b][hr]Nice script.  A couple of questions for you:   - Shouldn't there be a set of [ ] around the variables in case they contain special characters like blanks or SQL keywords?   - How can you handle special characters in the LIKE comparison if a string you would search for has a %, _, [ ], [^ ] or quotes? [/quote]I agree. It failed immediately for me for a column named "Group".		SET @Sql = 'SELECT @Row_Count = COUNT(*) '+			' FROM ' + @Table_Name + ' (NOLOCK) WHERE [' + @Column_Name + '] LIKE ''%' + @Search_For + '%'''Adding the brackets prevents the ambiguity of the word.Given that, I see this as a useful time-saver when a word or phrase may have been used in numerous places.Thanks!</description><pubDate>Fri, 08 Feb 2008 06:37:21 GMT</pubDate><dc:creator>Tim Wehr-392184</dc:creator></item><item><title>RE: Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>Nice script.  A couple of questions for you:   - Shouldn't there be a set of [ ] around the variables in case they contain special characters like blanks or SQL keywords?   - How can you handle special characters in the LIKE comparison if a string you would search for has a %, _, [ ], [^ ] or quotes? Toni</description><pubDate>Fri, 08 Feb 2008 06:13:28 GMT</pubDate><dc:creator>toniupstny</dc:creator></item><item><title>Find a text string in any column in a database.</title><link>http://www.sqlservercentral.com/Forums/Topic450524-1186-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/61777/"&gt;Find a text string in any column in a database.&lt;/A&gt;[/B]</description><pubDate>Fri, 01 Feb 2008 08:20:20 GMT</pubDate><dc:creator>Kenneth.Fisher</dc:creator></item></channel></rss>