日期:2014-05-17 浏览次数:20531 次
select * from topic where charindex('abc',title)>0 and charindex('英',title)>0 and charindex('语',title)>0
------解决方案--------------------
关键是把查询内容拆分成几个字符串,然后拼SQL:
declare @s varchar(50), @sql varchar(8000) set @sql = 'select * from topic where title like ''%' set @s = 'abc英语' declare @i int set @i = 1 while @i <= len(@s) begin if @i = 1 set @sql = @sql + substring(@s,@i,1) else begin if len(substring(@s,@i,1)) <> datalength(substring(@s,@i-1,1)) or datalength(substring(@s,@i,1)) = 2 set @sql = @sql + '%'' and title like ''%' + substring(@s,@i,1) else set @sql = @sql + substring(@s,@i,1) end set @i = @i + 1 end set @sql = @sql + '%''' exec(@sql)