如何在SQL SELECT语句中添加特定公司代码的部门例外规则?
解决方案
修改后的SQL语句如下:
select top (1000000) companyid ,companyfullname ,company_code ,division ,reportingname ,division_name ,country ,accountname from totaldw.dbo.companymap where company_code not in ('1760','1785','1831','1740') or (company_code = '1771' and division in ('01188','01189'))
逻辑说明
- 先从原排除列表中移除
1771,确保基础规则是排除1760、1785、1831、1740这几个公司代码的所有记录。 - 通过
OR追加例外判断:仅当公司代码为1771且对应的division是01188或01189时,保留该条记录,1771下其他division的记录仍会被排除。
内容的提问来源于stack exchange,提问作者courty340
相关产品推荐
相关产品推荐

