根据字符串评估创建新的位列

Create new bit column based on string evaluation

我正在研究函数 Contains 但它只能用于 Where 谓词,我正在寻找的是某种类型的东西

Select doc.* , IsSync = StringContains('Sync', doc.Url) from vw_Doc as doc

IsSync 现在将包含 1/0 或 true/false,具体取决于文档 Url 中是否存在单词 Sync。

这可能吗?

感谢您的宝贵时间

编辑:StringContains 是一个伪函数,它不是有效的语法

我会使用 case 和 charindex()。

select 
    doc.* , 
    case
        when charindex('Sync', doc.Url) > 0
            then 1
            else 0
        end as IsSync
from 
    vw_Doc as doc

Contains 不限于 where 从句,它 returns 是可以在各种上下文中使用的 boolean,例如:

select *,
  case when Contains( doc.url, 'Sync' ) then 1 else 0 end as IsSync
  from vw_Doc;