select title from ttt where
contains(TITLE,SELECT DISTINCT KEYWORD FROM TEM) --错了的
假设表tem有KEYWORD字段 表ttt 有Title字段 找出Title包含任意一个关键字的所有记录
谢谢
------解决方案--------------------
- SQL code
declare @sql varchar(1000)select @sql=isnull(@sql,'')+'or'+'"'+rtrim(KEYWORD)+'"' from TEM group by KEYWORDset @sql=STUFF(@sql,1,2,'')set @sql='select * from tttwhere contains(title,[email protected]+''')'exec (@sql)
------解决方案--------------------
你的想法实现不了
唯一的方法--用游标:
游标读取SELECT DISTINCT KEYWORD FROM TEM
对每个KEYWORD ,insert #temp select title from ttt where contains(TITLE,'KEYWORD')
最后显示数据,select distinct title from #temp