我们正在选择要导出的列以进行ERP / CRM同步。我们正在从GoldMine CRM中选择记录,并将其插入到我们的桥数据库中。它可以作为que,并且我们会间隔一定时间导入到ERP。使用下面的代码从插入的表中选择记录。对于状态(STATERES)和(C2.UCOUNTY),如果International为Y,则值可以为null。我如何将该条件添加到WHERE子句的AND语句中。相关代码在下面列出。 SQL SERVER 2008R
SELECT FROM inserted i
WHERE 1=1
...
AND C2.USTATERES IS NOT NULL--State Res, can be null, if International is Y
AND C2.UCOUNTY IS NOT NULL—County, can be null, if International is Y
...
SELECT FROM inserted i
WHERE 1=1
...
AND C2.USTATERES IS NOT NULL OR International = 'Y'--State Res, can be null, if International is Y
AND C2.UCOUNTY IS NOT NULL OR International = 'Y'—County, can be null, if International is Y
...
答案 0 :(得分:0)
通读代码,看来这是相关的部分:
AND C2.USTATERES IS NOT NULL--State Res, can be null, if International is Y
AND C2.UCOUNTY IS NOT NULL--County, can be null, if International is Y
要获得所需的结果,您只需要添加一个OR条件,该条件将在International为Y时通过该条件:
AND (C2.USTATERES IS NOT NULL OR C2.UINTERNAT = 'Y')--State Res, can be null, if International is Y
AND (C2.UCOUNTY IS NOT NULL OR C2.UINTERNAT = 'Y')--County, can be null, if International is Y
此解决方案确实假定您的i或C2表中存在“国际”字段。