明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

ASP中靈活使用Split()函數(shù)生成SQL查詢語句

[摘要]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