This is what I am trying to achieve in its simplest form:
SELECT p.ProductId, p.ProductName, p.SKU FROM tbl_Product p WHERE (p.ProductName LIKE '%white%' OR p.SKU LIKE '%white%') AND (p.ProductName LIKE '%cup%' OR p.SKU LIKE '%cup%')
I am trying to do this in UDF, which accepts a comma separated parameter for all search terms.
I tried to split this parameter into a temporary table and try the connection, for example:
DECLARE @SearchText nvarchar(1000) SELECT @SearchText='white,cup' DECLARE @SearchTerms TABLE (String nvarchar(200)) INSERT INTO @SearchTerms (String) SELECT '%' + String + '%' FROM dbo.CsvSplitString(@SearchText) SELECT p.ProductId, p.ProductName, p.SKU FROM tbl_Product p JOIN @SearchTerms s ON (p.ProductName LIKE s.String OR p.SKU LIKE s.String)
But this does not return what I want - it returns any records in which the name or SKU matches one of the search conditions. I need it to be returned as the first query, where the name or SKU matches all search queries (I think that makes sense).
It would be great thanks for pushing in the right direction - let me know if you need me to be more specific.
Note: Full-text search is currently not a viable option.
Thanks!
seanxe
source share