Here are sample steps:
1. Create linked server from SQL Server to your Analysis Services:
EXEC master.dbo.sp_addlinkedserver @server = N'VIDAS-LENOVO-ADVENTURE'
, @srvproduct=N'MSOLAP'
, @provider=N'MSOLAP'
, @datasrc=N'VIDAS-LENOVO'
, @catalog=N'Adventure Works DW'
go
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'VIDAS-LENOVO-ADVENTURE'
, @useself=N'False'
, @locallogin=NULL
, @rmtuser=NULL
, @rmtpassword=NULL
go
2. Get data from your SSAS database that will trigger e-mai.
Example, following query will get from Adventure Works Employee Actual Sales and Targeted Sales Amounts. Just records where Targeted Sales is more than Actual sale will be returned. You will save results in the table AdventureWorks.dbo.EmplSales:
SELECT [[Employee]].[Employee]].[Employee]].[MEMBER_CAPTION]]] AS EmployeeName
,[[Measures]].[Sales Amount Quota]]] AS SalesTargetAmount
,[[Measures]].[Reseller Sales Amount]]] AS SalesAmount
INTO AdventureWorks.dbo.EmplSales
FROM OPENQUERY([VIDAS-LENOVO-ADVENTURE]
, 'SELECT {[Measures].[Sales Amount Quota], [Measures].[Reseller Sales Amount]} ON 0
, NON EMPTY [Employee].[Employee].Children ON 1
FROM [Adventure Works]
WHERE ([Date].[Calendar].[Calendar Quarter].&[2004]&[1])' ) AS M
WHERE [[Measures]].[Sales Amount Quota]]] > [[Measures]].[Reseller Sales Amount]]]
3. Now you have table AdventureWorks.dbo.EmplSales. If you run query "SELECT * FROM AdventureWorks.dbo.EmplSales", this will be your results:
EmployeeName SalesTargetAmount SalesAmount Garrett R. Vargas 280000 245520.3631 Jae B. Pak 883000 778625.4236 Jillian Carson 714000 611129.0544 José Edvaldo. Saraiva 569000 502176.7795 Linda C. Mitchell 894000 851503.5759 Lynn N. Tsoflias 399000 335166.417 Michael G. Blythe 849000 728590.3421 Pamela O. Ansman-Wolfe 343000 287360.7647 Rachel B. Valdez 366000 338292.5434 Ranjit R. Varkey Chudukatil 707000 595612.6343 Shu K. Ito 614000 488129.3625 Stephen Y. Jiang 84000 72229.6073 Syed E. Abbas 7000 5313.012 Tete A. Mensa-Annan 454000 387635.9604 Tsvi Michael. Reiter 538000 483937.8403
Now you can use SQL Server stored procedure sp_send_dbmail to send results:
IF (SELECT COUNT(*) * FROM AdventureWorks.dbo.EmplSales) > 0
BEGIN
EXEC msdb.dbo.sp_send_dbmail @profile_name = 'AdventureWorks Administrator'
, @recipients = ' danw@Adventure-Works.com '
, @query = 'SELECT * FROM AdventureWorks.dbo.EmplSales'
, @subject = 'Employess that did not reach target'
, @attach_query_result_as_file = 1 ;
END
Of course, before starting to send e-mails, make sure that you setup your mail profiles. There are a lot of articles on the web that tells you how to do that.
When you have this SQL Code, you can add it as a separate SQL step after you finished processing (for example in SQL Server Jobs).