Check if string doesn't contain another string

前端 未结 4 1794
闹比i
闹比i 2021-02-02 05:11

In T-SQL, how would you check if a string doesn\'t contain another string?

I have an nvarchar which could be \"Oranges Apples\".

I would like to do

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-02 06:05

    Or alternatively, you could use this:

    WHERE CHARINDEX(N'Apples', someColumn) = 0
    

    Not sure which one performs better - you gotta test it! :-)

    Marc

    UPDATE: the performance seems to be pretty much on a par with the other solution (WHERE someColumn NOT LIKE '%Apples%') - so it's really just a question of your personal preference.

提交回复
热议问题