读书人

查询某Varchar列是否包含某一字符串的

发布时间: 2012-03-23 12:06:21 作者: rapoo

查询某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

读书人网 >SQL Server

热点推荐