ASP uses the split () function to generate SQL query statements

zhaozj2021-02-16  49

SPLIT program code

<% attribs = "Mall name ^^ fast food store name ^^ report"

Names = split (attrib s, "^^")

i = 0

For Each Name in Names

Response.Write Names (i) & "
"

i = i 1

NEXT%>

Split Results:

Mall name

Fast food store name

Stop name

Generate SQL statements based on split results

<% attribs = "Mall name ^^ fast food store name ^^ report"

Names = split (attrib s, "^^")

i = 0

SQL = "SELECT TOP 10 * from TableName Where"

For Each Name in Names

IF names (i) = "Mall name" THEN

SQL = SQL "Or Shopping Like '%" & Names (i) & "%'"

END IF

IF Names (i) = "Fast Food Store" THEN

SQL = SQL "OR Food Restaurant Like '%" & Names (I) & "%'"

END IF

IF names (i) = "Reporting Name" THEN

SQL = SQL "OR Food Restaurant Like '%" & Names (I) & "%'"

END IF

i = i 1

NEXT

SQL = SQL "Ordey By ID DESC"

SQL = Replace (SQL, "Where or", "where")

Response.write SQL%>

Program operation results:

SELECT TOP 10 * from Tablename WHERE Mall Like '% Shopping Mall Mall Name OR Fast Food Base Like'% Fast Food Store% 'OR Fast Food Hotel Like'% Retribution Name% 'Ordey By ID DESC

转载请注明原文地址:https://www.9cbs.com/read-24414.html

New Post(0)