posted 11/7/2009 12:38:15 PM by BrianKnight
In the last post (http://blogs.pragmaticworks.com/brian_knight/2009/09/calling-an-external-query-from-mdx.html), I showed you how to install an external assembly for Analysis Services to query a relational data set, whether in SQL Server or any other database like DB2. This enables you to close the loop as a user is analyzing the data to see live real-time data. Now that you have that installed, let’s create an action to open the recordset with a right-click action in Excel or most cube browsers.
To do this example, I’ll be using the AdventureWorks cube, which you can download here: http://msftasprodsamples.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=18652 and the assembly from my last post.
In this example, you’ll see how to navigate from the AdventureWorks cube to the AdventureWorksDW relational database, which will give the user more relational results back from the warehouse. Let’s start by adding a new action to the sample actions already in AdventureWorks as shown in the below image. Name the action whatever you wish and set the Target Type to Cells. You can also set it to an attribute or hierarchy. This option is really based on what you want the user to be able to right-click on to see your action. By setting the option to Cells, a user my right-click on a measure.
For the Action Expression option, use the following code. As you can see, it’s calling the assembly from my last blog, passing in the sample query and a parameter of the product name. Notice that the single-quotes have to be doubled up in some spots to handle the string product name being passed in. This can of course be a stored procedure as well.
"call PWSSASHelper.Query('provider=sqloledb;server=localhost;database=AdventureWorksDW;trusted_connection=yes','SELECT * FROM dbo.DimProduct where EnglishProductName = ''"+[Product].[Product].MemberValue+"''');"
If you want to get a bit more fancy, you can also change the caption (the default caption is the action name). In my case, I wanted to put the product name in the caption by setting the Caption as MDX option to true and using the following code for my caption:
"See All Info About: " + [Product].[Product].MemberValue
Here’s the complete action configuration:
Once complete and deployed, you’ll be able to browse the cube in Excel or in your favorite cube browser with action support and right-click on a measure and see the following caption and drill-through.
.
Once you select the drill through, you’ll be able to see a popup with the query’s data. In Excel, this would’ve opened in a new sheet.
BrianKnight (Member since: 10/22/2009 5:15:12 PM) Brian Knight, SQL Server MVP, MCITP, MCSE, MCDBA, is the owner and founder of Pragmatic Works. He is also the co-founder of SQLServerCentral.com and JumpstartTV.com. He runs the local SQL Server users group in Jacksonville (JSSUG). Brian is a contributing columnist at several technical magazines and does regular webcasts at Jumpstart TV. He is the author of 10 SQL Server books. Brian has spoken at conferences like PASS, SQL Connections and TechEd and many Code Camps. His blog can be found at http://www.pragmaticworks.com.
View BrianKnight 's profile
I read Brain Knight's excellent post on SSAS Rowset Actions right after I wrote a dll to do roughly the same thing. My dll works great when I hard code parameter values but I can't get the action code to work in SSAS. I have tried in vain for many hours :(
I would really appreciate it if anyone has a moment to point out my error.
This call works great from SSMS:
call sqlFetch.GetData('Provider=SQLNCLI10;Server=mcwbidev\Jaguar;Database=FinAdminDW; Trusted_Connection=yes','Select * from Common.dim_Installment where AwardID=0')
Notice the hard coded zero for the AwardId. Now I need to dynamically build the AwardId. The parameter is an int so this is what I tried (in SSAS on the Actions tab):
"call SqlFetch.GetData('Provider=SQLNCLI10;Server=mcwbidev\Jaguar;Database=FinAdminDW; Trusted_Connection=yes','Select * from Common.dim_Installment where AwardID = "+[Award].[Award Id].MemberValue+"');"
This fails with this error:
Execution of the managed stored procedure GetData failed with the following error: Exception has been thrown by the target of an invocation. Invalid column name '+[Award].[Award Id].MemberValue+'.
I'm pretty sure I'm making a silly error with the quotes but, I have tried many variations for hours without success.
Thanks in advance for any help resolving this issue!
Leave a comment
It's fast, easy and free! Submit articles, get your own blog, ask questions & give answers in the forums, and become a better developer, faster.
enter your email address: