t-sql测试数据仓库类型2变化

发布于 2024-10-14 12:14:31 字数 112 浏览 3 评论 0原文

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

我需要检查一行的有效日期是否与下一行的起始日期有效。

此检查是为了确保已结束的行也已正确开始,

谢谢,Marc

I need to look at a data warehouse and check that a type 2 change works correctly

I need to check that the vaild to date on a row is the same as the vaild from date on the next row.

This check is to make sure that a row has been ended has also been started correctly

thanks, Marc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2024-10-21 12:14:31

以下涉及 Kimball 2 型尺寸表。

请注意,这假定

  1. 3000-01-01 作为当前条目的遥远未来的日期。
  2. CustomerKey 是一个自动递增的整数。

此示例应该为您提供缺少或不匹配下一个条目的行列表。

;
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 ;

也有用

-- 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  ;

The following relates to Kimball type-2 dimension table.

Note that this assumes

  1. 3000-01-01 as a date in far future for the current entries.
  2. CustomerKey is an auto-incrementing integer.

This example should give you the list of rows with missing or miss-matched next-entries.

;
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 ;

Also useful

-- 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  ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文