日期:2014-05-18  浏览次数:20443 次

sql 语句中 如何判断 某个字符串 包含在另外一个字符串中
SQL code

--  比如    这个字符串  VLCT-28.ZML004N037-D01.MR.1ASE1YrSpcRule.FT1.551980057


---我想要判断   Yr   在不在   上面的字符串中

---如何 判断



------解决方案--------------------
SQL code
if charindex('Yr','VLCT-28.ZML004N037-D01.MR.1ASE1YrSpcRule.FT1.551980057')>0
 print '存在'
else
  print '不存在'

------解决方案--------------------
SQL code
declare @s varchar(100)=' VLCT-28.ZML004N037-D01.MR.1ASE1YrSpcRule.FT1.551980057'
if patindex('%Yr%',@s)>0
print 'Yr 在其中'
else 
print '不在其中'

------解决方案--------------------
SQL code

declare @s varchar(100)
SET @s=' VLCT-28.ZML004N037-D01.MR.1ASE1YrSpcRule.FT1.551980057'
if patindex('%Yr%',@s)>0
print '在'
else 
print '不在'

if @s LIKE '%Yr%'
print '在'
else 
print '不在'

if CHARINDEX('Yr',@s)>0
print '在'
else 
print '不在'
/*
在
在
在
*/