Search This Blog

Tuesday, September 14, 2010

Check / evaluate Multiple LIKES without Dynamic SQL


CREATE TABLE vTable (id INT, NAME VARCHAR(100))

INSERT INTO vTable

SELECT 1,'Shamas Qamar' UNION ALL
SELECT 2,'Atif' UNION ALL
SELECT 3,'Kashif' UNION ALL
SELECT 4,'Imran'


DECLARE @vParam VARCHAR(100)

SET @vParam = 'Sha,hif' 


SELECT * FROM vTable

CROSS APPLY (SELECT [value] FROM
dbo.fnSplit(@vParam,',')) b
WHERE NAME LIKE '%' + b.[VALUE] + '%'


DROP TABLE vTable


 Halo Reach

No comments:

Post a Comment