patternsqlMajor
8000 character limit on OPENQUERY against a linked server
Viewed 0 times
8000limitcharacteropenqueryagainstserverlinked
Problem
I have a query that I'm trying to run through
The character string that starts with [...] is too long. Maximum length is 8000.
Is there any way to work around this limitation?
For reference, I'm trying to run a query from SSRS through a linked MySQL Server.
OPENQUERY on SSRS/SQL Server 2014, but I keep getting an error of:The character string that starts with [...] is too long. Maximum length is 8000.
Is there any way to work around this limitation?
For reference, I'm trying to run a query from SSRS through a linked MySQL Server.
Solution
You can bypass the 8000 character limit of
In order to make sure this doesn't throw an error, you need to enable the
Or enabling it within the GUI:
OPENQUERY by utilizing EXECUTE AT, as follows:DECLARE @myStatement VARCHAR(MAX)
SET @myStatement = 'SELECT * FROM TABLE WHERE CHARACTERS.... ' -- Imagine that's longer than 8000 characters
EXECUTE (@myStatement) AT LinkedServerNameIn order to make sure this doesn't throw an error, you need to enable the
RPC OUT option on the linked server, by issuing the following command:EXEC master.dbo.sp_serveroption @server=N'LinkedServerName', @optname=N'rpc out', @optvalue=N'true'Or enabling it within the GUI:
Code Snippets
DECLARE @myStatement VARCHAR(MAX)
SET @myStatement = 'SELECT * FROM TABLE WHERE CHARACTERS.... ' -- Imagine that's longer than 8000 characters
EXECUTE (@myStatement) AT LinkedServerNameEXEC master.dbo.sp_serveroption @server=N'LinkedServerName', @optname=N'rpc out', @optvalue=N'true'Context
StackExchange Database Administrators Q#187522, answer score: 20
Revisions (0)
No revisions yet.