Storage processes are complex and complex, but they can support multiple logical characters. We can choose to search in this table and optimize the speed of stored procedures. So do you know the code implementation of the asp and stored procedures that search programs in the stored procedures? Let the editor of the Foot New Technology Channel take you to learn more about it!
asp function
The code copy is as follows: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
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'First remove the spaces at the end
m_strDest = ltrim(rtrim(m_strDest))
'Replace & , " and " etc. with +, -, spaces
m_strDest = replace(m_strDest , "&" , "+")
m_strDest = replace(m_strDest , " AND " , "+")
m_strDest = replace(m_strDest, " OR ", chr(32))
m_strDest = replace(m_strDest , "NOT " , "-")
'Initialize the variable to make the following loop go
m_intBeginPos = 1
do while m_intBeginPos <> 0
m_intBeginPos = instr(m_strDest,chr(32))
if m_intBeginPos <> 0 then 'If space is found
m_strHead = rtrim(ltrim(left ( m_strDest , m_intBeginPos )))
call print("[AnalyseKeyword()]: handles space m_strHead = " + m_strHead)
m_strTail = rtrim(ltrim(right (m_strDest , len(m_strDest) - m_intBeginPos)))
call print("[AnalyseKeyword()]: handles space m_strTail = " + m_strTail)
m_strDest = m_strHead + "*" + m_strTail
else
exit do
end if
loop
m_strDest = replace (m_strDest , "*" , chr(32))
call print("[AnalyseKeyword()]: After processing spaces, m_strDest = " + m_strDest)
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'First replace single quotes with double quotes
m_strDest = replace ( m_strDest , chr(39) , chr(34))
'Set an initial value to make the loop go
m_intBeginPos = 1
m_intEndPos =1
m_strHead = ""
m_strTail = ""
do while m_intBeginPos <> 0 and m_intEndPos <> 0
'If double quotes are found, note the starting position and look for the next double quote
m_intBeginPos = instr(m_strDest, chr(34))
if m_intBeginPos <> 0 then 'If the first quote is found
call print("[AnalyseKeyword()]: The location where the first quote appears: " + cstr(m_intBeginPos))
m_intEndPos = instr(m_intBeginPos + 1 , m_strDest ,chr(34))
if m_intEndPos <> 0 then 'If the second quote is found
call print("[AnalyseKeyword()]: Where the second quote appears: " + cstr(m_intEndPos))
'Separate the entire string into three paragraphs in quotes
call print ("[AnalyseKeyword()]: handles quotes m_strDest = " + m_strDest)
m_strHead = left(m_strDest , m_intBeginPos - 1)
call print ("[AnalyseKeyword()]: handles quotes m_strHead = " + m_strHead)
m_strMiddle = mid(m_strDest , m_intBeginPos + 1 , m_intEndPos - m_intBeginPos - 1)
call print ("[AnalyseKeyword()]: handles quotes m_strMiddle = " + m_strMiddle)
m_strTail = right(m_strDest , len(m_strDest) - m_intEndPos)
call print ("[AnalyseKeyword()]:m_strTail = " + m_strTail)
'If there is a + sign in the quotes, it will be processed as a character and temporarily replaced with other characters
m_strMiddle = replace(m_strMiddle , "+" , "|")
m_strDest = m_strHead + replace(rtrim(ltrim(m_strMiddle)) , chr(32) , "#") + m_strTail
else
exit do
end if
else
exit do
end if
loop
m_strDest = replace(m_strDest, chr(34) , "+")
call print ("[AnalyseKeyword()]: After processing quotation marks, m_strDest = " + m_strDest)
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Troubleshooting multiple plus signs, if you encounter multiple plus signs, you think it is a string, not a logical character
m_strDest = replace (m_strDest , "+++" ,"|||")
m_strDest = replace (m_strDest , "++" , "||")
call print ("[AnalyseKeyword()]: After processing multiple minus signs, m_strDest = '" + m_strDest + "'")
'Treat spaces on both sides of the plus sign
m_strDest = replace(m_strDest , " +" , "+")
m_strDest = replace(m_strDest , "+ " , "+")
m_strDest = replace(m_strDest , " + " , "+")
call print ("[AnalyseKeyword()]: After processing spaces on both sides of the minus sign m_strDest = '" + m_strDest + "'")
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Troubleshooting multiple minus signs, if you encounter multiple minus signs, you will think it is a string, not a logical character
m_strDest = replace (m_strDest , "---" ,"~~~~")
m_strDest = replace (m_strDest , "--" , "~~")
call print ("[AnalyseKeyword()]: After processing multiple minus signs, m_strDest = '" + m_strDest + "'")
'Treat spaces on both sides of the minus sign
m_strDest = replace(m_strDest , " -" , "-")
m_strDest = replace(m_strDest , "- " , "-")
m_strDest = replace(m_strDest , " - " , "-")
call print ("[AnalyseKeyword()]: After processing spaces on both sides of the plus sign m_strDest = '" + m_strDest + "'")
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if len(m_strDest) >= 3 then
m_strHead = left(m_strDest, 1)
m_strMiddle = mid(m_strDest , 2 , len(m_strDest) - 2)
m_strTail = right(m_strDest, 1)
if m_strHead = "+" or m_strHead = "-" then
m_strHead = ""
end if
if m_strTail = "+" or m_strTail = "-" then
m_strTail = ""
end if
m_strDest = m_strHead + m_strMiddle + m_strTail
end if
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
m_strDest = replace(m_strDest , "--" , "~~")
m_strDest = replace(m_strDest , "++" , "||")
m_strDest = replace(m_strDest, chr(32) , "@")
AnalyseKeyword = m_strDest
call print ("[AnalyseKeyword()]: After all processing is completed m_strDest = '" + m_strDest + "'")
end function
%>
Stored procedures
/************************************************************/
/* proc name: Up_ParseWordSearch */
/* */
/* Description: Keyword search */
/* */
/* parameters: @a_strCategoryID Category id */
/* @a_intPosition call location */
/* @a_strParseWord Search for keywords */
/* @a_intRowCount limits the maximum number of records to get */
/* */
/* date: 2000/6/28 */
/* */
/* author: Liuyunpeng */
/* */
/* history: */
/************************************************************/
if exists (select * from sysobjects where id = object_id("up_ParseWordSearch"))
drop proc up_ParseWordSearch
go
create proc up_ParseWordSearch @a_strParseword varchar(255),
@a_strCategoryID varchar(255),
@a_intPosition tinyint ,
@a_intRowCount int
as
declare @m_strSqlCondition varchar(255) --The conditional part of the Sql statement
declare @m_strSqlSelect varchar(255) --Sql statement selection part
declare @m_strSqlCategory varchar(100) --Category part of sql statement
/*Defend the selection part of sql based on the call location*/
select @m_strSqlSelect
= case
When @a_intPosition = 4 then --Product library
"select ProductID , 'Title' = ProductName , 'Description' = left(Description , 100) "
+ " from Product where "
When @a_intPosition = 5 then --Business Opportunity Library
"select ID , Title ,'Description' = left(convert(varchar,content) , 100) "
+ " from BusinessChance where "
When @a_intPosition = 6 then --Company Library
"select CompanyID , 'Title' = CompanyName , 'Description' =left(Description , 100) "
+ " from Company where "
end
/*Defend the classification part of sql based on the classification ID*/
select @m_strSqlCategory
= case
when @a_strCategoryID <> "0" then " CategoryID like '" + @a_strCategoryID + "%' and "
else ""
end
/*Determine the conditional part of sql based on the call location*/
select @m_strSqlCondition
= case
When @a_intPosition = 4 --Product
then "(ProductName like '%" + @a_strParseWord + "%'"
+ " or Description like '%" + @a_strParseWord + "%'"
+ " or ProducerName like '%" + @a_strParseWord + "%') "
When @a_intPosition = 5 --Business Opportunities
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
The above is the code implementation of the search program in asp and stored procedures. I believe everyone has a certain understanding. If you want to know more technical information, please continue to pay attention to the wrong new technology channel!