首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >t-sql测试数据仓库类型2的更改

t-sql测试数据仓库类型2的更改
EN

Stack Overflow用户
提问于 2011-01-26 20:03:41
回答 1查看 410关注 0票数 1

我需要查看数据仓库并检查类型2更改是否正确工作

我需要检查一行上的vaild to date与下一行上的vaild from date是否相同。

此检查是为了确保已结束的行也已正确启动

谢谢,马克

EN

回答 1

Stack Overflow用户

发布于 2011-01-26 21:37:04

下面是关于Kimball类型2维度表的内容。

请注意,这里假设

当前entries.

  • CustomerKey的远期日期
  1. 3000-01-01是一个自动递增的整数。

此示例应给出缺少或未匹配next条目的行的列表。

代码语言:javascript
复制
;
with
q_00 as  (
select
      CustomerKey
    , CustomerBusinessKey
    , rw_ValidFrom
    , rw_ValidTo
    , row_number() over (partition by CustomerBusinessKey order by CustomerKey asc) as rn
from dimCustomer
)
select
      a.CustomerKey
    , a.CustomerBusinessKey
    , a.rw_ValidFrom
    , a.rw_ValidTo
    , b.CustomerKey          as b_key
    , b.CustomerBusinessKey  as b_bus_key
    , b.rw_ValidFrom         as b_ValidFrom
    , b.rw_ValidTo           as b_ValidTo
from      q_00 as a
left join q_00 as b on b.CustomerBusinessKey = a.CustomerBusinessKey and (b.rn = a.rn + 1) 
where a.rw_ValidTo < '3000-01-01'
  and a.rw_ValidTo != b.rw_ValidFrom ;

也很有用

代码语言:javascript
复制
-- Make sure there are no nulls
-- for rw_ValidFrom, rw_ValidTo
select
      CustomerKey
    , rw_ValidFrom
    , rw_ValidTo
from dimCustomer
where rw_ValidFrom is null
   or rw_ValidTo   is null ;

-- make sure there are no duplicates in  rw_ValidFrom
-- for the same customer
select
      CustomerBusinessKey
    , rw_ValidFrom
    , count(1) as cnt
from dimCustomer
group by CustomerBusinessKey, rw_ValidFrom
having count(1) > 1  ;

-- make sure there are no duplicates in  rw_ValidTo
-- for the same customer
select
      CustomerBusinessKey
    , rw_ValidTo
    , count(1) as cnt
from dimCustomer
group by CustomerBusinessKey, rw_ValidTo
having count(1) > 1  ;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4804357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档