当前位置: 代码迷 >> Sql Server >> 查询某Varchar列是否包含某一字符串的Sql语句解决方案
  详细解决方案

查询某Varchar列是否包含某一字符串的Sql语句解决方案

热度:84   发布时间:2016-04-27 14:31:43.0
查询某Varchar列是否包含某一字符串的Sql语句
table1中有一列col1,类型为varchar,其中有一行col1的内容为'abcdef'

要实现

select * from table1 where 'cde' in col1

或者

select * from table1 where col1 have 'cde'

该怎么写SQL语句呢?

------解决方案--------------------
SQL code
select * from table1 where col1 like '%cde%'--或是select * from table1 where charindex('cde',col1)>0
------解决方案--------------------
SQL code
declare @table1 table (col1 varchar(6))insert into @table1select 'aaa' union allselect 'abcdef' union allselect 'asdf' union allselect 'gasd' union allselect 'ssss'select * from @table1 where col1 like '%cde%'--或是select * from @table1 where charindex('cde',col1)>0 /*col1------abcdef*/
------解决方案--------------------
探讨
SQL code

declare @table1 table (col1 varchar(6))
insert into @table1
select 'aaa' union all
select 'abcdef' union all
select 'asdf' union all
select 'gasd' union all
select 'ssss'

select *……

------解决方案--------------------
探讨
SQL code
select * from table1 where col1 like '%cde%'

--或是

select * from table1 where charindex('cde',col1)>0

------解决方案--------------------
SQL code
select * from table1 where col1 like '%cde%'
------解决方案--------------------
探讨

SQL code
select * from table1 where col1 like '%cde%'

--或是

select * from table1 where charindex('cde',col1)>0
  相关解决方案