Yak Posting Veteran
Posted - 05/07/2013 : 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'