假设我们有一个具有此值的列:
bla dibla
哪个(CONTAINS?)搜索表达式可用于使用此搜索字符串查找上述条目:
bladibla
答案 0 :(得分:2)
我担心用全文搜索来搜索这样的字符串是不可能的,因为MSSQL会分析行并从字符串中获取“单词”(标记)。因此,如果您有值bla dibla
,MSSQL会将其拆分为两个单词bla
和dibla
。
要解决您的问题,您可以这样做:
(replace([Value],' ',''))
CREATE TABLE [dbo].[TestTable](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Value] [nvarchar](max) NOT NULL,
[ValueTrimed] AS (replace([Value],' ','')) PERSISTED,
CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED
([Id] ASC)
INSERT INTO TestTable
(Value)
Values
('bla dibla')
SELECT *
FROM [dbo].[TestTable] as tt
where CONTAINS (tt.ValueTrimed, 'bladibla')
SELECT *
FROM [dbo].[TestTable] as tt
INNER JOIN FREETEXTTABLE([dbo].[TestTable], ValueTrimed, 'bladibla') AS KEY_TBL ON tt.Id = KEY_TBL.[KEY];