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 2012 Forums
 Transact-SQL (2012)
 Search All tables for a word like 'Red'

Author  Topic 

wafw1971
Yak Posting Veteran

75 Posts

Posted - 2013-05-07 : 05:07:13
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

52326 Posts

Posted - 2013-05-07 : 06:06:50
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 - 2013-05-07 : 10:40:58
All sorted now thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-08 : 00:27:03
welcome

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

- Advertisement -