同一情况下的两个条件,其中一个检查 SQL Server 2012 中是否包含子字符串

Two conditions in the same case, one of them check if contains substring in SQL Server 2012

我的 .NET 项目中有一个 post 部署脚本。

在部署时,我想根据某些条件更新一些行。

这是我目前拥有的:

DECLARE @BRANDS NVARCHAR(500) = 'http://example.com/';

UPDATE [ServiceVersion]
SET [ExternalUrl] as = CASE 
        WHEN (
                SELECT [ExternalUrl]
                FROM [ServiceVersion]
                WHERE [GatewayPath] = '/proxy/brands'
                ) != @BRANDS
            THEN @BRANDS
        END
WHERE [GatewayPath] = '/proxy/brands'

如果该行不等于我的变量,则更新它。否则它什么都不做。

我更想做的是,添加另一个条件,比如 x !=BRAND && string does not contain "abc" update.

但是如何在检查子字符串的 CASE 中添加另一个条件?

试试这个...

DECLARE @BRANDS NVARCHAR(500) = 'http://example.com/';

UPDATE [ServiceVersion]
SET [ExternalUrl] = @BRANDS         
WHERE
      [ExternalUrl] != @BRANDS 
      AND [ExternalUrl] not like '%abc%'
      AND [GatewayPath] = '/proxy/brands'

希望对您有所帮助!