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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Search All tables for a word like 'Red'
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wafw1971
Yak Posting Veteran

75 Posts

Posted - 05/07/2013 :  05:07:13  Show Profile  Reply with Quote
I want to be able to search for different words like Red or Blue or Fry and bring back a distinct list using a WHERE clause, I have written my query below but it doesn't seem to be bringing anything back can you tell what I have done wrong?

DECLARE @Test VARCHAR (200)
SET @Test = @Test

SELECT H.Name, O.Name AS Owner, S.SilksName, T.Name AS Trainer, J.FirstName + ' ' + J.LastName AS Jockey
FROM Horse AS H LEFT OUTER JOIN
Owner AS O ON CHARINDEX(@Test, O.Name) <> 0 LEFT OUTER JOIN
Trainer AS T ON CHARINDEX(@Test, T.Name) <> 0 LEFT OUTER JOIN
Silks AS S ON CHARINDEX(@Test, S.SilksName) <> 0 LEFT OUTER JOIN
Jockey AS J ON CHARINDEX(@Test, J.FirstName) <> 0 OR
CHARINDEX(@Test, J.LastName) <> 0

WHERE @Test LIKE 'Red'

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 05/07/2013 :  06:06:50  Show Profile  Reply with Quote
sounds like this

http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

wafw1971
Yak Posting Veteran

75 Posts

Posted - 05/07/2013 :  10:40:58  Show Profile  Reply with Quote
All sorted now thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 05/08/2013 :  00:27:03  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000