简体   繁体   English

MDS中的TSQL业务规则列表

[英]TSQL list of business rules in MDS

I need help with querying my business rules in SQL! 我需要查询SQL中的业务规则的帮助!

I have created couple of business rules in MDS web service to validate my master data and found out that 2 % of my data is not complying with the rules. 我已经在MDS Web服务中创建了几个业务规则来验证我的主数据,并发现我的数据中有2%不符合规则。 Now I have created a SQL subscription view to report on the invalid data in PowerBI. 现在,我已经创建了一个SQL订阅视图,以报告PowerBI中的无效数据。 In my PowerBI report I need to tell the business user why the data is invalid but I cannot since the subscription view only tells where the data is invalid but not why the data is invalid. 在我的PowerBI报告中,我需要告诉业务用户为什么数据无效,但是我不能告诉用户,因为订阅视图仅表明数据无效的地方,而不是为什么数据无效的原因。 So I need to know how I might query my business rules from MDS database in SQL and map it with my PowerBI data model. 因此,我需要知道如何从SQL中的MDS数据库查询业务规则,并将其与PowerBI数据模型进行映射。 Is there a way to query the list of business rules from MDS database? 有没有一种方法可以从MDS数据库查询业务规则列表?

OK, so there are multiple ways to go about this. 好的,因此有多种方法可以解决此问题。 Here are some solutions, pls choose one that suits your scenario. 这里有一些解决方案,请选择一种适合您的方案。

1. SQL - List of all Business Rules 1. SQL-所有业务规则列表

The following query will retrieve the list of all Active Business Rules created in MDS. 以下查询将检索在MDS中创建的所有活动业务规则的列表。

SELECT *
  FROM [MDM].[mdm].[viw_SYSTEM_SCHEMA_BUSINESSRULES]
  WHERE Model_Name = 'YourModelName'
  AND BusinessRule_StatusName = 'Active'

You can, of course, further filter by Entity_Name , etc. The important columns in your case are going to be: 当然,您可以按Entity_Name等进一步过滤。在您的情况下,重要的列将是:

  • [BusinessRule_Name]
  • [BusinessRule_Description]
  • [BusinessRule_RuleConditionText]
  • [BusinessRule_RuleActionText]

Note: The challenge in your scenario, I think, is going to be that the Subscription View of the entity does not have IDs of the exact Business Rules that failed. 注意:我认为,您的方案所面临的挑战将是该实体的“订阅视图”不具有失败的确切业务规则的ID。 So I'm not sure how you'll tie these 2 together (failing Rows -> List of Business Rules). 因此,我不确定您如何将这两个捆绑在一起(失败行->业务规则列表)。 Also remember that each row may have more than 1 business rule that failed. 还要记住,每一行可能有多个失败的业务规则。

2. using View viw_SYSTEM_USER_VALIDATION 2.使用视图viw_SYSTEM_USER_VALIDATION

This is a view that has a historical list of all business rules (+row info) that failed. 此视图具有所有失败的业务规则(+行信息)的历史列表。 You may use the view in this way: 您可以通过以下方式使用视图:

SELECT 
    DISTINCT ValidationIssue_ID, Version_ID, VersionName, Model_ID, ModelName, Entity_ID, EntityName, Hierarchy_ID, HierarchyName, Member_ID, MemberCode, MemberType_ID, MemberType, ConditionText, ActionText, BusinessRuleID, BusinessRuleName, PriorityRank, DateCreated, NotificationStatus_ID, NotificationStatus
FROM [MDM].[mdm].[viw_SYSTEM_USER_VALIDATION]
 WHERE --CAST(DateCreated as DATE) = CAST(GETDATE() as DATE) AND
    ModelName = 'YourModelName'
    --AND EntityName IN ('Entity_1','Entity_2') -- Use this to Filter on specific Entities

Here, use the columns Model_ID , Entity_ID and Member_ID / MemberCode to identify the specific model, entity & row that failed. 在这里,使用Model_IDEntity_IDMember_ID / MemberCode来标识失败的特定模型,实体和行。

Columns BusinessRuleName , ConditionText & ActionText will give your users additional info on the Business Rule that failed. BusinessRuleNameConditionTextActionText将为您的用户提供有关失败的业务规则的其他信息。

Note: 注意:

  • One issue with using this view is that even though, let's say, your failure condition was resolved the next day by the user, the view will still show that on a certain date, a validation had failed. 使用此视图的一个问题是,即使说用户第二天解决了您的失败情况,该视图仍会显示在某个日期验证失败。 (via column DateCreated ). (通过DateCreated列)。
  • Also note that the same failed data row will appear multiple times here if multiple Business Rules on the same row failed validation (there will be different BusinessRuleID/Name, etc). 还要注意,如果同一行上的多个业务规则验证失败,则同一失败数据行将在此处多次出现(会有不同的BusinessRuleID / Name等)。 Just something to take note of. 只是要注意的事情。
  • Similarly, the same row may appear multiple times if it has failed again & again at different times. 同样,如果同一行在不同的时间再次失败,则该行可能会出现多次。 To workaround this, and if your final report can do with that, add a WHERE clause on the DateCreated column so that you only get to see any row that Failed today. 要解决此问题,并且如果最终报告可以解决此问题,请在DateCreated列上添加WHERE子句,以便仅查看今天失败的任何行。 The commented out line of code <--CAST(DateCreated as DATE) = CAST(GETDATE() as DATE) AND> does the same. 注释掉的代码行<--CAST(DateCreated as DATE) = CAST(GETDATE() as DATE) AND>执行相同的操作。 If you can't use that, just make sure the data row are distinct. 如果您不能使用它,只需确保数据行是不同的。 However, if you do this, remember that if something Failed yesterday (and is still in the Failed status), it may not show up. 但是,如果执行此操作,请记住,如果昨天发生某项故障(并且仍处于“故障”状态),则该故障可能不会显示。

My suggestion would be to use a slightly modified version of Solution #2: 我的建议是使用解决方案2的稍作修改的版本:

Get the list of Failed Rows from your Subscription View (the data row's ValidationStatus is actually still 'Failed' ), then JOIN with viw_SYSTEM_USER_VALIDATION making sure that you only select the row with MAX(DateCreated) value (of course for the same data row AND Business Rule). 从您的订阅视图中获取失败行的列表(数据行的ValidationStatus实际上仍为 'Failed' ),然后使用viw_SYSTEM_USER_VALIDATION进行联接,以确保仅选择具有MAX(DateCreated)值的行(当然,同一数据行并业务规则)。

Best of luck and if you find anything else while solving this issue, do share your learning here with all of us. 祝您好运,如果您在解决此问题时发现任何其他问题,请与我们所有人分享您的经验。

Lastly, if you found this useful, pls remember to Mark it as the Answer :) 最后,如果您发现此功能有用,请记住将其标记为答案:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM