select case when col like '%ada%' then 1 else 0 end from tb
case when col is null then 'NULL' else 0 end
MSSQL有 charindex DECLARE @document varchar(64)SELECT @document = 'Reflectors are vital safety' + ' components of your bicycle.' SELECT CHARINDEX('bicycle', @document) GO
select case when col like '%ada%' then 1 when col is null then 'null' else 0 end from tablename
楼主应该问的是一个问题吧,判断并且考虑null? select case when ifnull(v1,v2) like '%XXXXX%' then 1 else 0 end from xxxxxx 用coalesce(v1,v2)更好,几乎所有db都适用 不过,没测试过,需要验证一下,也忙有的db版本不支持case when中再加function
MYSQL楼主搞错字符了吧
from tb
DECLARE @document varchar(64)SELECT @document = 'Reflectors are vital safety' +
' components of your bicycle.'
SELECT CHARINDEX('bicycle', @document)
GO
select case when col like '%ada%' then 1 when col is null then 'null' else 0 end
from tablename
select case when ifnull(v1,v2) like '%XXXXX%' then 1 else 0 end from xxxxxx
用coalesce(v1,v2)更好,几乎所有db都适用
不过,没测试过,需要验证一下,也忙有的db版本不支持case when中再加function