Tải bản đầy đủ - 0 (trang)
6-1. Importing Data from SQL Server Analysis Services

6-1. Importing Data from SQL Server Analysis Services

Tải bản đầy đủ - 0trang

Chapter 6 ■ Miscellaneous Data Sources


Use SQL Server Integration Services (SSIS) and the Microsoft OLEDB provider to connect to Analysis Services

and import the data in tabular format. This is done as follows:


Create a new Integration Services package. Add a Data Flow task to the Control Flow

pane. Double-click to switch to the Data Flow pane—or click the Data Flow tab,

if you prefer.


Right-click in the Connection Managers tab at the bottom of the screen. Select New

OLEDB Connection. Click New.


Select Native OLEDB\Microsoft OLEDB Provider for Analysis Services 11.0. Enter

the Analysis Services server name — localhost in this example. Choose Integrated

Security. You can then select the cube to which you wish to connect from the Initial

Catalog drop-down list. You should see something like Figure 6-1.

Figure 6-1.  OLEDB connection to an OLAP cube



Chapter 6 ■ Miscellaneous Data Sources


Test the connection. Click OK twice to finish creating it.


Add an OLEDB source task to the Data Flow pane. Select the OLEDB connection

manager that you just created. Select SQL Command as the Data Access Mode,

and enter the MDX (MultiDimensional eXpression) code required to select the

data you wish to import. An example is follows

(C:\SQL2012DIRecipes\CH06\ProductsAndClients.Mdx in the sample files):


NON EMPTY([Dim Clients].[Client Name].[Client Name]) ON COLUMNS

,EXCEPT([Dim Products].[Make].[Make], [Dim Products].[Make].UNKNOWNMEMBER) ON ROWS

FROM [Car Sales DW]

WHERE [Measures].[Cost Price]

The dialog box should look something like Figure 6-2.

Figure 6-2.  An MDX query in an OLEDB source



Chapter 6 ■ Miscellaneous Data Sources


Click Preview to see if the connection and MDX selection work. You could get the

following alert (see Figure 6-3), which need not worry you.

Figure 6-3.  OLAP warning


Click OK, and you should see your sample data.


Click OK to confirm the data source creation. SSIS once again complains and displays

the warning dialog box. Click OK to close it.


Add a Data Conversion task onto the Data Flow pane, and join the OLEDB source

task to it. You now need to convert all numeric data from DT_WSTR (Unicode string)

to the required data type in your ultimate SQL Server table. So double-click the Data

Conversion task to open it. Select the input columns that you wish to modify, and

then map them to the required output data types. This simple example looks like

Figure 6-4.



Chapter 6 ■ Miscellaneous Data Sources

Figure 6-4.  Conversion of OLAP source data


Click OK to confirm the data conversion.


 dd an OLEDB destination to the Data Flow pane, connect the Data Conversion task


to it, and double-click the OLEDB destination. Select or create an OLEDB connection

manager, and then click New to create a destination table. Accept the table

specification, but change the name to a name which you prefer. Click OK to confirm

the table creation.


 lick Mappings. Ensure that the source and destination data columns are connected.


Click OK to close the dialog box.

You can now execute the package and import the data from Analysis Services.

How It Works

Counterintuitive as it may sound, there are occasions when you may need to import data from an SQL Server

Analysis Services database back into an SQL Server relational table. This could be because



Chapter 6 ■ MisCellaneous Data sourCes

You prefer to use the aggregations that already exist in an OLAP cube rather than

re-create parallel queries in T-SQL that are not only more complex to write, but can also

take longer to return results.

The OLAP cube contains data from sources to which you do not have access—and it is

faster and easier to source this data from Analysis Services.

The SSAS cube is the enterprise’s “single version of the truth” and you are obliged to use

the data that it contains.

The hard work is done by the OLEDB provider for Analysis Services, based on the MDX that you must write.

The MDX can be as simple—or as complex—as you wish. However, you might prefer to write and test the MDX

query in SQL Server Management Studio, as the OLEDB Source query builder will not let you build MDX. It will

parse the query, however.

Otherwise, this is a fairly standard SSIS Data Flow task. You will need, at a minimum, connection rights

to the OLAP data source. The warning dialog box appears if you try to see the source data columns, or indeed

every time that you do almost anything in the data source task. Just take no notice. Interestingly, SSAS returns

everything as text—so you need to convert all numeric data to an appropriate numeric data type.

You need to ensure that the MDX you use returns two-dimensional tabular data, with only single columns

and row headings. After all, you are importing multidimensional data into a “two-dimensional” SQL database.

You can also alias columns using MDX, as shown in a Recipe 6-3, which can be worth the extra effort.

Hints, Tips, and Traps

If you are using a previous version of SQL Server instead of the Native OLEDB\Microsoft

OLEDB Provider for Analysis Services 11.0, choose the provider version 10.0 for SQL

Server 2008 and version 9.0 for SQL Server 2005.

If you get an error when testing the connection in older versions of Analysis Services, click

All in step 4 and add Format = Tabular to the Extended Properties.

It is worth noting that where the OLEDB source task says SQL Command Text, it in fact

means “pass-through query.” You can send through any query that is in a dialect that the

source server expects and can handle. Here it must be MDX.

6-2. Importing Data from an Analysis Services Cube

on a Regular Basis


You want to import data from an Analysis Services database on a regular basis using a T-SQL command, but

without developing a structured ETL process.


Set up a linked server to connect to an Analysis Services database and import the data in tabular format. You can

do it as follows.


Configure the MSOLAP provider to allow in-process connections, as described in the

Recipe 4-7.


Expand Server Objects, followed by Linked Servers, and then Providers. Right-click




Chapter 6 ■ Miscellaneous Data Sources


Select Properties, and then select Allow Inprocess, as shown in Figure 6-5.

Figure 6-5.  OLAP linked server provider


Click OK.


From SQL Server Management Studio, run the following T-SQL snippet to create a

linked server (C:\SQL2012DIRecipes\CH06\OLAPLinkedServer.Sql). You will need to

specify your own Analysis Services server for the @datasrc parameter:

EXEC master.dbo.sp_addlinkedserver

@server = N'CarSales',







Tài liệu bạn tìm kiếm đã sẵn sàng tải về

6-1. Importing Data from SQL Server Analysis Services

Tải bản đầy đủ ngay(0 tr)