SQL Server 2008 CTE 和 CONTAINSTABLE 语句 - 为什么会出现错误?
我正在测试将数据库从 SQL Server 2005 迁移到 2008。我们使用 CTE 进行分页。
使用全文 CONTAINSTABLE 时,CTE 将不会运行并生成错误。
这是我的非工作代码 -
WITH results AS (
SELECT ROW_NUMBER() over (ORDER BY GBU.CreateDate DESC ) as rowNum,
GBU.UserID,
NULL AS DistanceInMiles
FROM User GBU WITH (NOLOCK)
WHERE 1=1
AND GBU.CountryCode IN (SELECT [Value] FROM fn_Split('USA',','))
AND GBU.UserID IN (SELECT [KEY] FROM CONTAINSTABLE(VW_GBU_Search, *, 'COMPASS'))
)
SELECT * from results
WHERE rowNum BETWEEN 0 and 25
如果我注释掉 CONTAINSTABLE 行,则该语句将执行。如果我只运行 SELECT 语句(而不是WITH),则该语句执行得很好。
我在这方面遇到的无用错误是:
消息 0,级别 11,状态 0,行 0 A 当前发生严重错误 命令。如果有结果的话,应该 被丢弃。消息 0,级别 20,状态 0,第 0 行发生严重错误 当前命令。结果,如果 任何,都应该被丢弃。
有什么建议吗?
I am testing out moving our database from SQL Server 2005 to 2008. We use CTE's for paging.
When using full-text CONTAINSTABLE, the CTE will not run and generates an error.
Here's my non-working code-
WITH results AS (
SELECT ROW_NUMBER() over (ORDER BY GBU.CreateDate DESC ) as rowNum,
GBU.UserID,
NULL AS DistanceInMiles
FROM User GBU WITH (NOLOCK)
WHERE 1=1
AND GBU.CountryCode IN (SELECT [Value] FROM fn_Split('USA',','))
AND GBU.UserID IN (SELECT [KEY] FROM CONTAINSTABLE(VW_GBU_Search, *, 'COMPASS'))
)
SELECT * from results
WHERE rowNum BETWEEN 0 and 25
If I comment out the CONTAINSTABLE line, the statement executes. If I only run the SELECT statement (not the WITH), the statement executes fine.
The un-helpful error I get on this is:
Msg 0, Level 11, State 0, Line 0 A
severe error occurred on the current
command. The results, if any, should
be discarded. Msg 0, Level 20, State
0, Line 0 A severe error occurred on
the current command. The results, if
any, should be discarded.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎是一个错误。请参阅 http://connect.microsoft.com/SQLServer/feedback/ViewFeedback .aspx?FeedbackID=426981
听起来修复应该在下一个 MSSQL SP 中。
Appears to be a bug. See http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=426981
Sounds like the fix should be in the next MSSQL SP.
假设其他答案是正确的,并且根本问题是一个错误,因为您没有从 CONTAINSTABLE 引用 RANK,也许像下面这样的查询将是一种解决方法,其中“ID”是 VW_GBU_Search 中的 ID 列(未经测试) )?
另外,为什么有“1=1”条款?你能消除它吗?
Assuming the other answers are correct, and that the underlying issue is a bug, since you aren't referencing RANK from CONTAINSTABLE, perhaps a query something like the following would be a workaround, where "ID" is the ID column in VW_GBU_Search (untested)?
Also, why do you have the "1=1" clause? Can you eliminate it?
我在这个问题上头撞墙好几个小时;这是一个解决方法:
I banged my head against the wall on this problem for hours; here is a workaround: