Search code examples
stringt-sqlcontains

Create new bit column based on string evaluation


I was looking into the function Contains but it can only be used in the Where predicate, what I'm looking for is something of the sorts

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

IsSync now would contain 1/0 or true/false, depending if the word Sync exists in the document Url.

Is this at all possible ?

Thank you for your time

Edit: StringContains is meant as a pseudo-function, it's not valid syntax


Solution

  • I would use case and charindex().

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