有時候我們需要根據參數來實現多種條件查詢,這裡就是透過split函數將參數分割成多個
Split 程式碼
複製代碼代碼如下:
<%attribs="商場名^^速食店名^^報停名"
names=Split(attribs,"^^")
i=0
for each name in names
response.write names(i)&"<br>"
i=i+1
next
%>
程序拆分結果:
商場名
速食店名
報停名
根據Split 結果產生SQL 語句
複製代碼代碼如下:
<%attribs="商場名^^速食店名^^報停名"
names=Split(attribs,"^^")
i=0
sql="select top 10 * from TableName where"
for each name in names
if names(i)="商場名" then
sql=sql+" or 商場like '%"&names(i)&"%'"
end if
if names(i)="速食店名" then
sql=sql+" 或 速食店like '%"&names(i)&"%'"
end if
if names(i)="報停名" then
sql=sql+" 或 速食店like '%"&names(i)&"%'"
end if
i=i+1
next
sql=sql+" Ordey by Id DESC"
sql=Replace(sql, "where or", "where")
response.write sql
%>
程式運行結果:
複製代碼代碼如下:
select top 10 * from TableName where 商場like '%商場名%' or 快餐店like '%快餐店名%' or 快餐店like '%報停名%' Ordey by Id DESC