首页 > 解决方案 > SP 在条件指定不返回时返回匹配项

问题描述

我的 SP 应该只返回字段 GTid1 <> Gtid2 的记录。但是,当我运行此 sp 然后在 Visual Studio 中加载我的报告时,下面是 SP 中用于提取此报告所需数据的 SQL。它应该返回 LEI1 与 LEI 2 匹配但 GTID1 <> GTID2 的数据

例子 :

GTID1 = G0101 LEI:E12345 GTID2:G0201 LEI:E12345

 select  distinct
    @reportIdLeiDuplicates,
    wp1.CrmPartyId,
    wp1.GtId,  
    convert(varchar(20), 
            hashbytes('SHA1', isnull(wp1.CrmPartyId, '') + isnull(wp1.GtId, '') ),  
            2), 
    (select AttributeId from REPORTING.Attribute where Name = 'GT ID'),                     @WeccoSysId,        wp1.GtId,
    (select AttributeId from REPORTING.Attribute where Name = 'CRM Party Id'),              @WeccoSysId,        wp1.CrmPartyId,
    (select AttributeId from REPORTING.Attribute where Name = 'Legal Name'),                @WeccoSysId,        wp1.LegalName,
    (select AttributeId from REPORTING.Attribute where Name = 'Business Class'),            @WeccoSysId,        wp1.BusinessClass,
    (select AttributeId from REPORTING.Attribute where Name = 'Relationship Manager Name'), @WeccoSysId,        wp1.RmFullName,     
    (select AttributeId from REPORTING.Attribute where Name = 'PbeName'),                   @WeccoSysId,        wp1.PbeFullName,            
    (select AttributeId from REPORTING.Attribute where Name = 'Overall Status'),            @WeccoSysId,        wp1.OverallStatus,
    (select AttributeId from REPORTING.Attribute where Name = 'LEI'),                       
[![enter image description here][1]][1]@WeccoSysId,     wp1.Lei,
    (select AttributeId from REPORTING.Attribute where Name = 'GT ID'),                     
 @WeccoSysId,       wp2.GtId,
    (select AttributeId from REPORTING.Attribute where Name = 'CRM Party Id'),              @WeccoSysId,        wp2.CrmPartyId,
    (select AttributeId from REPORTING.Attribute where Name = 'Legal Name'),                
 @WeccoSysId,       wp2.LegalName,
    (select AttributeId from REPORTING.Attribute where Name = 'Business 
 Class'),           @WeccoSysId,        wp2.BusinessClass,
    (select AttributeId from REPORTING.Attribute where Name = 'Relationship 
   Manager Name'), @WeccoSysId,        wp2.RmFullName,      
    (select AttributeId from REPORTING.Attribute where Name = 'PbeName'),                   
       @WeccoSysId,     wp2.PbeFullName,            
    (select AttributeId from REPORTING.Attribute where Name = 'Overall 
 Status'),          @WeccoSysId,        wp2.OverallStatus,
    (select AttributeId from REPORTING.Attribute where Name = 'LEI'),                       
     @WeccoSysId,       wp2.Lei

 from       core.WeccoParty         wp1
 join   CORE.WeccoParty wp2                      on  wp1.Lei  = wp2.Lei
  where wp1.Lei                                   is not null
                                             and wp1.GtId < wp2.GtId
                                             and wp2.Lei is not null

标签: sqlvisual-studio-2012

解决方案


推荐阅读