Ja, muligt med fuldtekstsøgning, og sandsynligvis det bedste svar. For en lige T-SQL-løsning kan du bruge en split-funktion og join, f.eks. forudsat en tabel med tal kaldet dbo.Numbers (du skal muligvis beslutte dig for en anden øvre grænse):
SET NOCOUNT ON;
DECLARE @UpperLimit INT;
SET @UpperLimit = 200000;
WITH n AS
(
SELECT
rn = ROW_NUMBER() OVER
(ORDER BY s1.[object_id])
FROM sys.objects AS s1
CROSS JOIN sys.objects AS s2
CROSS JOIN sys.objects AS s3
)
SELECT [Number] = rn - 1
INTO dbo.Numbers
FROM n
WHERE rn <= @UpperLimit + 1;
CREATE UNIQUE CLUSTERED INDEX n ON dbo.Numbers([Number]);
Og en opdelingsfunktion, der bruger denne tabel med tal:
CREATE FUNCTION dbo.SplitStrings
(
@List NVARCHAR(MAX)
)
RETURNS TABLE
AS
RETURN
(
SELECT DISTINCT
[Value] = LTRIM(RTRIM(
SUBSTRING(@List, [Number],
CHARINDEX(N',', @List + N',', [Number]) - [Number])))
FROM
dbo.Numbers
WHERE
Number <= LEN(@List)
AND SUBSTRING(N',' + @List, [Number], 1) = N','
);
GO
Så kan du blot sige:
SELECT key, NvarcharColumn /*, other cols */
FROM dbo.table AS outerT
WHERE EXISTS
(
SELECT 1
FROM dbo.table AS t
INNER JOIN dbo.SplitStrings(N'list,of,words') AS s
ON t.NvarcharColumn LIKE '%' + s.Item + '%'
WHERE t.key = outerT.key
);
Som en procedure:
CREATE PROCEDURE dbo.Search
@List NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON;
SELECT key, NvarcharColumn /*, other cols */
FROM dbo.table AS outerT
WHERE EXISTS
(
SELECT 1
FROM dbo.table AS t
INNER JOIN dbo.SplitStrings(@List) AS s
ON t.NvarcharColumn LIKE '%' + s.Item + '%'
WHERE t.key = outerT.key
);
END
GO
Så kan du bare sende @List
ind (f.eks. EXEC dbo.Search @List = N'foo,bar,splunge'
) fra C#.
Dette vil ikke være super hurtigt, men jeg er sikker på, at det vil være hurtigere end at trække alle data ud i C# og dobbelt-nestede det manuelt.