Sample Header Ad - 728x90

8000 character limit in OPENQUERY against Analysis Server

5 votes
2 answers
2047 views
I have a query like
SELECT column1, column2 FROM OPENQUERY(AnalysisServerName, 'MDX QUERY ...').
It is inside a stored procedure. A MDX query is dynamically built in it and the length of the query much longer than 8000 characters (can reach up to 400 000 signs). The MDX query returns something about 200 columns and I need only some of them. I am not able to reduce the amount because of dimensions complexity. So, I have to write results to a temporary table or directly SELECT them as the result of the procedure. I decided to SELECT them. But, when I try to omit the limitation of 8000 characters with EXEC OPENQUERY(AnalysisServerName, 'MDX QUERY ...') AT AnalysisServerName, I can't SELECT or even save them to a temporary table as it happens inside the stored procedure and nesting is not allowed (following [this thread](https://stackoverflow.com/q/1492411/13828439])) . I wish I can do
SELECT column1, column2 FROM (EXEC OPENQUERY(AnalysisServerName, 'MDX Query') AT AnalysisServerName)
Even if I can execute a very long MDX query directly on Analysis Server
DECLARE @myStatement VARCHAR(MAX)
SET @myStatement = 'OPENQUERY(AnalysisServerName, 'MDX Query')'

EXECUTE (@myStatement) AT AnalysisServerName
I can't do anything with the results in my stored procedure, because
DECLARE @myStatement VARCHAR(MAX)
SET @myStatement = 'SELECT column1, column2 FROM OPENQUERY(AnalysisServerName, 'MDX Query')'

EXECUTE (@myStatement) AT AnalysisServerName
is not allowed. --- So what can I do in such situation? I need to - query Analysis Service with OPENQUERY, - handle the query of length greater than 8000, - save the results to a temporary table or select them directly.
Asked by AKedzierski (51 rep)
Jul 28, 2021, 11:12 AM
Last activity: Jul 29, 2021, 04:29 PM