SQL 服务器自由文本 Varbinary returns 没有,转换 VARBINARY -> VARCHAR 不工作
SQL Server Freetext Varbinary returns nothing and Conversion VARBINARY -> VARCHAR Not working
嘿,我的解决方案有一些问题,我想不出来
下面是我的创作table
CREATE TABLE FreeTextSearch
(
[ID] BIGINT NOT NULL IDENTITY(1,1),
[Content] VARBINARY(MAX) NOT NULL,
[SubjectClass] VARCHAR(30) NOT NULL,
[SubjectID] VARCHAR(30) NOT NULL,
[ColumnName] VARCHAR(128) NOT NULL,
CONSTRAINT PK_FreeTextSearch PRIMARY KEY (ID)
);
ALTER TABLE FreeTextSearch
Add FileExtension As '.html';
CREATE INDEX FreeTextSearch_SubjectClass
ON FreeTextSearch ([SubjectClass]);
CREATE FULLTEXT CATALOG [freetext_catalog]
CREATE FULLTEXT INDEX ON FreeTextSearch
(
[Content] TYPE COLUMN FileExtension
)
KEY INDEX PK_FreeTextSearch ON freetext_catalog;
这将创建一个 FreeTextSearch table,FileExtension 为 HTML 等
我已经根据触发器自动将数据转换为 VARBINARY 插入到 table 中,但现在有两个问题
内容如:
<p>Test note for free text bla!</p>
不会被像
这样的查询检测到
SELECT
Id,
CONVERT(VARCHAR(MAX), [Content]) AS [Content]
FROM dbo.FreeTextSearch
WHERE FREETEXT ([Content], 'Test')
另外
SELECT
Id,
CONVERT(VARCHAR(MAX), [Content]) AS [Content]
FROM dbo.FreeTextSearch
会 return
ID: 1 Content <
ID: 2 Content <
同时
SELECT
Id,
CONVERT(XML, [Content]) AS [Content]
FROM dbo.FreeTextSearch
会Return
ID: 1 Content: <p>Test note for free text bla!</p>
ID: 2 Content: <p>Something is very wrong with this one i think</p><p>Not really sure what.</p>
哪个数据是正确的,但不清楚原因
- FREETEXT 没有找到任何东西
- 为什么只有 VARCHAR(MAX) returns <
select test, cast(test as varchar(max)), cast(test as nvarchar(max))
from
(
select cast('a' as varbinary(max)) + 0x0 /* nul in ascii, anything after that not printed*/ + cast('123' as varbinary(max)) as test
) as src;
select test, cast(test as varchar(max)), cast(test as nvarchar(max))
from
(
select cast(N'<p>Test note for free text bla!</p>' as varbinary(max)) as test
) as src;
嘿,我的解决方案有一些问题,我想不出来
下面是我的创作table
CREATE TABLE FreeTextSearch
(
[ID] BIGINT NOT NULL IDENTITY(1,1),
[Content] VARBINARY(MAX) NOT NULL,
[SubjectClass] VARCHAR(30) NOT NULL,
[SubjectID] VARCHAR(30) NOT NULL,
[ColumnName] VARCHAR(128) NOT NULL,
CONSTRAINT PK_FreeTextSearch PRIMARY KEY (ID)
);
ALTER TABLE FreeTextSearch
Add FileExtension As '.html';
CREATE INDEX FreeTextSearch_SubjectClass
ON FreeTextSearch ([SubjectClass]);
CREATE FULLTEXT CATALOG [freetext_catalog]
CREATE FULLTEXT INDEX ON FreeTextSearch
(
[Content] TYPE COLUMN FileExtension
)
KEY INDEX PK_FreeTextSearch ON freetext_catalog;
这将创建一个 FreeTextSearch table,FileExtension 为 HTML 等
我已经根据触发器自动将数据转换为 VARBINARY 插入到 table 中,但现在有两个问题
内容如:
<p>Test note for free text bla!</p>
不会被像
这样的查询检测到 SELECT
Id,
CONVERT(VARCHAR(MAX), [Content]) AS [Content]
FROM dbo.FreeTextSearch
WHERE FREETEXT ([Content], 'Test')
另外
SELECT
Id,
CONVERT(VARCHAR(MAX), [Content]) AS [Content]
FROM dbo.FreeTextSearch
会 return
ID: 1 Content <
ID: 2 Content <
同时
SELECT
Id,
CONVERT(XML, [Content]) AS [Content]
FROM dbo.FreeTextSearch
会Return
ID: 1 Content: <p>Test note for free text bla!</p>
ID: 2 Content: <p>Something is very wrong with this one i think</p><p>Not really sure what.</p>
哪个数据是正确的,但不清楚原因
- FREETEXT 没有找到任何东西
- 为什么只有 VARCHAR(MAX) returns <
select test, cast(test as varchar(max)), cast(test as nvarchar(max))
from
(
select cast('a' as varbinary(max)) + 0x0 /* nul in ascii, anything after that not printed*/ + cast('123' as varbinary(max)) as test
) as src;
select test, cast(test as varchar(max)), cast(test as nvarchar(max))
from
(
select cast(N'<p>Test note for free text bla!</p>' as varbinary(max)) as test
) as src;