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

关于模糊查询(帮顶有分)
怎样实现在字符串 "1,2,3,4,5,6 "(该字符串是不确定的)中用查询字符串 "1,2,4,5,6 "(该字符串也是不确定的)模糊查询,得到包含字符串 "1,2,3,4,5,6 "的记录!
      望各位高手不吝赐教,谢谢~~~~


------解决方案--------------------
where ... like '% '+ '1,2,3,4,5,6 '+ '% '
------解决方案--------------------
怎样实现在字符串 "1,2,3,4,5,6 "(该字符串是不确定的)中用查询字符串 "1,2,4,5,6 "(该字符串也是不确定的)模糊查询,得到包含字符串 "1,2,3,4,5,6 "的记录!
望各位高手不吝赐教,谢谢~~~~

select * from tb where charindex( ', ' + '1,2,4,5,6 ' + ', ' , ', ' + col + ', ') > 0
------解决方案--------------------
用charindex
------解决方案--------------------
按顺序包含么?

用 "2,1,4,5,6 "查能不能得到 "1,2,3,4,5,6 "?

------解决方案--------------------

建议楼主去做个分词吧,把拆开的字符去模糊查询
------解决方案--------------------
haha

------解决方案--------------------
MARK
------解决方案--------------------
mark
------解决方案--------------------
PatIndex( '% '+Replace(@Language, ', ', '% ')+ '% ',ULI_Language)> 0
---这样?????
--------------------------------------
Create Proc MoreConditionSlect @Habitation varchar(100),@Sex char(1),@Eduction varchar(10),
@WorkTime varchar(20),@NowJobtype varchar(50),
@NowJobName varchar(50),@ISManage char(1),
@Area varchar(30),@Trade varchar (50),@RefurbishTime DateTime,
@Language varchar(20),@LS varchar(10),@StartTime DateTime,@EndTime DateTime,@Company varchar(50)
AS
select UB_UserName,UB_Tname,UB_Brithday,UB_Habitation,UB_SEX,UB_Eduction,UB_WorkTime,UJ_NowJobtype,UEI_Company,UJ_Nowtrade,UJ_NowJobName,UJ_ISManage,UJ_Area,UJ_Trade,UR_RefurbishTime,ULI_Language,ULI_LS from (select a.*,b.*,c.*,d.*,e.* from dbo.U_Base_Info as a, dbo.U_Job_Intent as b,dbo.U_Resume_Manage as c,dbo.U_Lang_Info as d,dbo.U_Experience_Info as e where a.UB_UserName = b.UJ_UserName and b.UJ_UserName = c.UR_BelongUser and c.UR_BelongUser = d.ULI_UserName and d.ULI_UserName = e.UEI_UserName and e.UEI_Btime in (select max(UEI_Btime) from dbo.U_Experience_Info group by dbo.U_Experience_Info.UEI_UserName ) ) as Exp1
where ( UB_Habitation like '% '+@Habitation+ '% ' or @Habitation = ' ' ) and
( UB_SEX like '% '+@Sex+ '% ' or @Sex = ' ' ) and
( UB_Eduction like '% '+@Eduction+ '% ' or @Eduction = ' ' ) and
( UB_WorkTime like '% '+@WorkTime+ '% ' or @WorkTime = ' ' ) and
( UJ_NowJobtype like '% '+@NowJobtype+ '% ' or @NowJobtype = ' ' ) and
( UJ_NowJobName like '% '+@NowJobName+ '% ' or @NowJobName = ' ' ) and
( UJ_ISManage like '% '+@ISManage+ '% ' or @ISManage = ' ' ) and
(
(PatIndex( '% '+Replace(@Language, ', ', '% ')+ '% ',ULI_Language)> 0) or ULI_Language = ' '
) and
( UJ_Area like '% '+@Area+ '% ' or @Area = ' ' ) and
( UJ_Trade like '% '+@Trade+ '% ' or @Trade = ' ' ) and