ASP中靈活使用Split()函數(shù)生成SQL查詢語句
發(fā)表時(shí)間:2023-08-12 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]Split 程序代碼<%attribs="商場(chǎng)名^^快餐店名^^報(bào)停名"names=Split(attribs,"^^")i=0for each nam...
Split 程序代碼
<%attribs="商場(chǎng)名^^快餐店名^^報(bào)停名"
names=Split(attribs,"^^")
i=0
for each name in names
response.write names(i)&"<br>"
i=i+1
next%>
程序拆分結(jié)果:
商場(chǎng)名
快餐店名
報(bào)停名
根據(jù) Split 結(jié)果生成 SQL 語句
<%attribs="商場(chǎng)名^^快餐店名^^報(bào)停名"
names=Split(attribs,"^^")
i=0
sql="select top 10 * from TableName where"
for each name in names
if names(i)="商場(chǎng)名" then
sql=sql+" or 商場(chǎng) like '%"&names(i)&"%'"
end if
if names(i)="快餐店名" then
sql=sql+" or 快餐店 like '%"&names(i)&"%'"
end if
if names(i)="報(bào)停名" then
sql=sql+" or 快餐店 like '%"&names(i)&"%'"
end if
i=i+1
next
sql=sql+" Ordey by Id DESC"
sql=Replace(sql, "where or", "where")
response.write sql%>
程序運(yùn)行結(jié)果:
select top 10 * from TableName where 商場(chǎng) like '%商場(chǎng)名%' or 快餐店 like '%快餐店名%' or 快餐店 like '%報(bào)停名%' Ordey by Id DESC