By Evan Schmidt
Here are the steps required to download data from an SSAS cube using MDX within a SQL statement.
Avoid double hop authentication issues
Since need to use windows authentication to access the cube you may get an error due to “double hop” authentication.
To avoid this use one of the following methods:
1) Run the MDX/SQL on your local instance of SQL server
2) Run the SQL under a SQL Agent job which where the service is a running under a valid domain account
3) Set-up Kerberos to avoid the double hop issue
4) Remote desktop into the host server
Create a linked server
EXEC master.dbo.sp_addlinkedserver @server = N’ LINKEDSERVERNAME’, @srvproduct=N’ssas’, @provider=N’MSOLAP’, @datasrc=N’SERVERNAME’, @catalog=N’CUBENAME’
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N’LINKEDSERVERNAME’,@useself=N’True’,@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL
Use open query to execute the MDX
SELECT *
FROM OpenQuery(LINKEDSERVERNAME, ‘SELECT [MEASURES].[Count] on 0 FROM CUBENAME’) as X