比较复杂,可以支持多种逻辑符,包括 + - and or 空格等,并且根据需要随便增加。可以根据条件选择在那个表中搜索,对速度也做了优化,可以说是很快的。当然因为是以前写的,存在不少毛病。存储过程中用到几乎所有sql server的特性,如光标(记录集分页)等。好了,不吹了,自己看程序吧。
asp 函数 复制代码 代码如下: function AnalyseKeyword(a_strSource) dim m_strDest , m_intLoop dim m_intBeginPos , m_intEndPos dim m_strHead , m_strMiddle , m_strTail m_strDest = a_strSource
else exit do end if else exit do end if loop m_strDest = replace(m_strDest , chr(34) , "+") call print ("[AnalyseKeyword()]:处理引号完毕后m_strDest = " + m_strDest)
/*根据调用位置决定sql的选择部分*/ select @m_strSqlSelect = case when @a_intPosition = 4 then --商品库 "select ProductID , "Title" = ProductName , "Description" = left(Description , 100) " + " from Product where " when @a_intPosition = 5 then --商业机会库 "select ID , Title ,"Description" = left(convert(varchar,content) , 100) " + " from BusinessChance where " when @a_intPosition = 6 then --公司库 "select CompanyID , "Title" = CompanyName , "Description" =left(Description , 100) " + " from Company where " end
/*根据分类ID决定sql的分类部分*/ select @m_strSqlCategory = case when @a_strCategoryID <> "0" then " CategoryID like "" + @a_strCategoryID + "%" and " else "" end
/*根据调用位置决定sql的条件部分*/ select @m_strSqlCondition = case when @a_intPosition = 4 --商品 then "(ProductName like "%" + @a_strParseWord + "%"" + " or Description like "%" + @a_strParseWord + "%"" + " or ProducerName like "%" + @a_strParseWord + "%") " when @a_intPosition = 5 --商业机会 then "(Title like "%" + @a_strParseWord + "%"" + " or Keyword like "%" + @a_strParseWord + "%") " when @a_intPosition = 6 then "(CompanyName like "%" + @a_strParseWord + "%"" + " or Description "%" + @a_strParseWord + "%") " end
set rowcount @a_intRowCount exec (@m_strSqlSelect + @m_strSqlCategory + @m_strSqlCondition) set rowcount 0 go