【问题标题】:Highlighting the differences in matched rows between two tables突出显示两个表之间匹配行的差异
【发布时间】:2019-09-21 03:52:13
【问题描述】:

我正在构建一个报告,它将告诉我两个表中的数据是否在特定列中匹配。到目前为止,我能够在对面表中找到哪些行不匹配,但现在我想知道 - 有没有办法突出显示哪一列不匹配?即显示哪些数据不匹配,无论是数量、佣金等。假设交易日期、经纪人和代码必须匹配。

请记住,这些表的结构不同,但确实有一些共同的列名。

我根据以下内容匹配表格:

t = table1 和 tt = table2

WHERE  NOT EXISTS (SELECT * 
                   FROM   @table2 tt 
                   WHERE  t.broker = tt.broker 
                          AND ( t.ticker = tt.ticker 
                                 OR t.isin = tt.isin 
                                 OR t.sedol = tt.sedol 
                                 OR t.cusip = tt.cusip ) 
                          AND t.[trade date] = tt.[trade date] 
                          AND t.quantity = tt.quantity 
                          AND ABS(t.[gross commission]) = ABS(tt.[gross commission])
                  ) 
       AND t.[gross commission] <> 0 

【问题讨论】:

  • 样本数据和期望的结果真的很有帮助。
  • highlight 怎么样?

标签: sql reporting-services ssrs-2008


【解决方案1】:

如果您只是想使用一个列来告诉您在哪里查找差异,一种选择是连接两个表并创建一个列,当它们在各自表中的值不匹配时,该列基本上连接列名.类似的东西..

concat_ws(',',
case when t.broker<> tt.broker then 'broker' end,
case when t.ticker <> tt.ticker then 'ticker' end,
case when t.isin <> tt.isin then 'isin'  end,
case when t.sedol <> tt.sedol then 'sedol' end,
case when t.cusip <> tt.cusip ) then 'cusip' end,
case when t.[trade date]<> tt.[trade date] then 'trade date' end,
case when t.quantity <> tt.quantity then 'quantity' end,
case when ABS(t.[gross commission]) <> ABS(tt.[gross commission]) then 'gross commission' end) as unmatched_columns

【讨论】:

    猜你喜欢
    • 2018-01-06
    • 2022-12-07
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2011-01-19
    • 2017-11-02
    相关资源
    最近更新 更多