OPENQUERY对链接服务器的字符限制为8000个


10

我有一个要OPENQUERY在SSRS / SQL Server 2014上运行的查询,但是我不断收到以下错误:

以[...]开头的字符串太长。最大长度为8000。

有什么办法可以解决此限制?

作为参考,我正在尝试通过链接的MySQL Server从SSRS运行查询。

Answers:


12

您可以OPENQUERY利用来绕过8000个字符的限制EXECUTE AT,如下所示:

DECLARE @myStatement VARCHAR(MAX)
SET @myStatement = 'SELECT * FROM TABLE WHERE CHARACTERS.... ' -- Imagine that's longer than 8000 characters

EXECUTE (@myStatement) AT LinkedServerName

为了确保这不会引发错误,您需要RPC OUT通过发出以下命令在链接服务器上启用该选项:

EXEC master.dbo.sp_serveroption @server=N'LinkedServerName', @optname=N'rpc out', @optvalue=N'true'

或在GUI中启用它:

在此处输入图片说明

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.