THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Master Data Services Team

Blog for the Microsoft SQL Server Master Data Services (MDS) team. Blog posts are contributed by various team members.

Subscription Views - Part 2: Combining and Customizing Views

(this post was contributed by Val Lovicz, Principal Program Manager on the MDS Team)


This post is the second in a series on Subscription Views in SQL Server 2008 R2 Master Data Services (“MDS”). In the first post, I described how to create standard subscription views. In this post I will describe how to create your own custom views that build upon the standard views.

This post gives SQL examples that assume you have already created the “_ProductHierarchyLevels” view and the “_ProductLeafAttributes” view as described in the first post.

For those new to SQL scripting and editing in SQL Server Management Studio, refer to Books Online for more information.

Example 1: Filtering Rows and Columns

The standard subscription views may have more rows and columns than your export process needs. To improve query performance and produce only the subset of data that you need, consider building your own custom view on top of a standard, generated subscription view. For example, suppose you only wanted the level columns from the “Product Management” hierarchy. The following example SELECT statement specifically queries the level columns and filters the rows to the “Product Management” hierarchy only.

SELECT [Leaf_Code]
FROM [mdm].[_ProductHierarchyLevels]
WHERE Hierarchy = 'Product Management'

To further this example, you could save this SELECT statement as your own custom view in the database by adding a CREATE VIEW statement at the beginning:

CREATE VIEW _ProductsPMHierarchy AS
SELECT [Leaf_Code]
FROM [mdm].[_ProductHierarchyLevels]
WHERE Hierarchy = 'Product Management'

Note: If you need to make changes to the view definition and recreate it, issue a DROP VIEW command as follows.

DROP VIEW _ProductsPMHierarchy

Example 2: Joining Multiple Views

Another common requirement is combining attribute and hierarchy data together. Suppose you need a view combining both the Product Management hierarchy levels and the Product attributes. You can achieve this by creating a simple custom view with a JOIN on two standard subscription views. The following example SQL will create a new view “_ProductsAndPMHierarchy”.

CREATE VIEW _ProductsAndPMHierarchy AS
SELECT pa.[Member_ID]
FROM [mdm].[_ProductLeafAttributes] pa
INNER JOIN [mdm].[_ProductHierarchyLevels] hl ON pa.Member_ID=hl.Leaf_ID
WHERE hl.Hierarchy = 'Product Management'

In this example, I have aliased the views as “pa” for “product attributes” and “hl” for “hierarchy levels”. Note that the two views have been joined on the common member key value in pa.Member_ID and hl.Leaf_ID. As in the first view, I have limited the hierarchy content to the Product Management hierarchy. When generating this SELECT statement, there is no need to type all these column names by hand; see Scripting a Table for more information on generating an initial SELECT statement.

Once the view is created, we can select from the new view and see the combined set of columns. As shown below, the view now contains both hierarchy level columns and attribute columns for each product row.


With a little creativity and SQL scripting, the standard subscription views can be customized to produce nearly any output view format you may need.

Legal Notice

© 2010 Microsoft Corporation. All rights reserved. This information is provided “as-is”. Information and views expressed, including URL and other Internet Web site references, may change without notice. You bear the risk of using this information. Examples are provided for illustration only. Provision of this information does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this information for your internal, reference purposes only.

Published Wednesday, March 03, 2010 3:10 PM by MDS Team
Filed under:


No Comments
New Comments to this post are disabled
Privacy Statement