- SQL code
set @sql=N'SELECT a.ID,Title,AddDate ' [email protected]+ ' a INNER JOIN @Products b ON CHARINDEX(b.keyWord,a.Title)>0 WHERE CONTAINS(Title,@contains) GROUP BY a.ID,Title,AddDate ORDER BY Sum(keyNum) DESC,COUNT(DISTINCT keyword),AddDate desc'print @sqlexec sp_executesql @sql
@tablename 接受参数作为表名
@Products是一个根据关键词顺序生成的权重表
@contains是关键词组合
最终输出的SQL语句为
- SQL code
SELECT a.ID,Title,AddDate FS_News a INNER JOIN @Products b ON CHARINDEX(b.keyWord,a.Title)>0 WHERE CONTAINS(Title,@contains) GROUP BY a.ID,Title,AddDate ORDER BY Sum(keyNum) DESC,COUNT(DISTINCT keyword),AddDate desc消息 102,级别 15,状态 1,第 1 行'a' 附近有语法错误。
------解决方案--------------------
你用全局临时表,##Products